
  ___  ____  ____  ____  ____ ®
 /__    /   ____/   /   ____/      Stata 18.0
___/   /   /___/   /   /___/       MP—Parallel Edition

 Statistics and Data Science       Copyright 1985-2023 StataCorp LLC
                                   StataCorp
                                   4905 Lakeway Drive
                                   College Station, Texas 77845 USA
                                   800-782-8272        https://www.stata.com
                                   979-696-4600        service@stata.com

Stata license: 745-user 2-core network, expiring 30 Jun 2025
Serial number: 501809309429
  Licensed to: Noah Sobel-Lewin
               University of Chicago

Notes:
      1. Stata is running in batch mode.
      2. Unicode is supported; see help unicode_advice.
      3. More than 2 billion observations are allowed; see help obs_advice.
      4. Maximum number of variables is set to 5,000 but can be increased;
          see help set_maxvar.

. do 01Code/trading/00MainStata.do 

. *clear all
. clear matrix

. set more off

. set linesize 255

. pause on

. version 15

. 
. ** This will be called from the top level of the entire replication
. global CODE_DIR = "01Code/trading"

. 
. global BASELINE_DATA_IN = "00RawData/baseline"

. global BASELINE_DATA_OUT = "02DataPipeline/baseline"

. global EMISSIONS_DATA_OUT = "02DataPipeline/emissions"

. global TRADING_DATA_IN = "00RawData/trading"

. global TRADING_DATA_OUT = "02DataPipeline/trading/intermediate"

. global TRADING_DATA_CLEAN = "02DataPipeline/trading/cleaned"

. 
. global TRADING_TABS="03Output/tables"

. global TRADING_FIGS="03Output/figures"

. 
. ** We use a conversion rate of USD 1 to INR 70, as of 2 Jan 2019, 
. ** Source: The Fed (https://www.federalreserve.gov/releases/h10/20190107/)
. global USD2INR=70

. 
. 
. ********************************************************************************
. 
. ** Create intermediate data sets
. do "$CODE_DIR/construct_datasets/clean_inventory_data.do"

. /************************************************************************
> Purpose:        Create a plant-period NeML Inventory data set.
> 
> Notes:      The final product is a plant-period NeML inventory data set 
>                     (N=156, T=10) with following columns:
>                         * gpcb_id: plant unique id
>                         * commodity: commodity unique id
>                         * allocated_quantity: initial permit allocation (kg)
>                         * sold: permits sold in a period (kg)
>                         * purchase: permits purchased in a period (kg)
>                         * consumed: validated emissions in a period (kg)
>                         * current_inventory: permits left by the end of a period (kg)
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. ********************************************************************************
. *** Generate a data set of trading plants baseline covariates
. ********************************************************************************
. 
. use "$EMISSIONS_DATA_OUT/Rule0_Panel.dta", clear
(337 STACKS. MASTER T&C BALANCED PANEL. HIST CALIB FACTORS.)

. drop if D_treatment == 0
(3,264 observations deleted)

. keep gpcb_id D_cyc D_scr D_bf D_esp cyc_max bf_max scr_esp_max num_cyclones num_scrubbers num_bagfilters num_esps plant_total_heatoutput ln_plant_total_heatoutput

. duplicates drop

Duplicates in terms of all variables

(3,588 observations deleted)

. 
. order gpcb_id plant_total_heatoutput ln_plant_total_heatoutput

. label var gpcb_id "Plant GPCB ID"

. save "$TRADING_DATA_OUT/covariates_plant.dta", replace
(file 02DataPipeline/trading/intermediate/covariates_plant.dta not found)
file 02DataPipeline/trading/intermediate/covariates_plant.dta saved

. 
. keep gpcb_id

. save "$TRADING_DATA_OUT/index_plant.dta", replace
(file 02DataPipeline/trading/intermediate/index_plant.dta not found)
file 02DataPipeline/trading/intermediate/index_plant.dta saved

. 
. ********************************************************************************
. *** Clean NeML Inventory data
. ********************************************************************************
. 
. import delimited "$TRADING_DATA_IN/NeMLinventory_Sept2019-Mar2021.csv", clear
(9 vars, 43,136 obs)

. gen mydate = date(date,"YMD") 

. sort mydate gpcb_id

. drop date 

. rename mydate date

. format date %tddd-Mon-CCYY

. 
. gen commodity_period = .
(43,136 missing values generated)

. replace commodity_period = 1 if commodity == "PSUM160919"
(3,607 real changes made)

. replace commodity_period = 2 if commodity == "PSUM161019"
(3,116 real changes made)

. replace commodity_period = 3 if commodity == "PSUM161119"
(6,440 real changes made)

. replace commodity_period = 4 if commodity == "PSUM010120"
(4,115 real changes made)

. replace commodity_period = 5 if commodity == "PSUM010220"
(3,774 real changes made)

. replace commodity_period = 6 if commodity == "PSUM010320"
(2,608 real changes made)

. replace commodity_period = 7 if commodity == "PSUM011220"
(5,121 real changes made)

. replace commodity_period = 8 if commodity == "PSUM010121"
(4,620 real changes made)

. replace commodity_period = 9 if commodity == "PSUM010221"
(4,785 real changes made)

. replace commodity_period = 10 if commodity == "PSUM010321"
(4,950 real changes made)

. drop if commodity_period == .
(0 observations deleted)

. 
. preserve

. keep commodity commodity_period

. duplicates drop

Duplicates in terms of all variables

(43,126 observations deleted)

. label var commodity "Commodity ID"

. label var commodity_period "Commodity period number"

. save "$TRADING_DATA_OUT/index_commodity-period.dta", replace
(file 02DataPipeline/trading/intermediate/index_commodity-period.dta not found)
file 02DataPipeline/trading/intermediate/index_commodity-period.dta saved

. restore

. 
. ********************************************************************************
. *** Check duplicated record
. ********************************************************************************
. 
. gsort gpcb_id commodity_period date sold purchased

. gen temp = 1

. bysort gpcb_id commodity date: egen sum_temp = sum(temp)

. gsort gpcb_id commodity_period date sold purchased

. 
. ********************************************************************************
. *** Output a plant-commodity-date panel
. ********************************************************************************
. 
. by gpcb_id commodity_period date: gen last_record_of_day = (_n == _N)

. keep if last_record_of_day == 1
(115 observations deleted)

. drop last_record_of_day temp sum_temp

. order gpcb_id commodity commodity_period date

. 
. replace gpcb_id = 1732028288 if gpcb_id == 158777056
(0 real changes made)

. destring gpcb_id, replace
gpcb_id already numeric; no replace

. * 43,021 (plant, commodity, day) observations
. 
. label var gpcb_id "Plant GPCB ID"

. label var commodity "Commodity ID"

. label var commodity_period "Commodity period number"

. label var date "Date"

. label var allocated_quantity "Permits allocated (kg) from NeML inventory data"

. label var blocked "Quantities of bids blocked (kg) from NeML inventory data"

. label var sold "Quantities of bids sold (kg) from NeML inventory data"

. label var purchased "Quantities of bids purchased (kg) from NeML inventory data"

. label var consumed "Quantities of bids consumed (kg) from NeML inventory data"

. label var current_inventory "Quantities of bids not consumed (kg) from NeML inventory data"

. 
. preserve

. * Undo GPCB's period VII covid policy in which they reduced emissions
. * for certain plants during the true-up period. 
. * Calculate cumulative maximum of consumed emissions.
. * Save for later use
. keep if commodity_period == 7
(37,906 observations deleted)

. 
. gen cummax_consumed = consumed

. sort commodity_period gpcb_id date

. bys commodity_period gpcb_id: replace cummax_consumed = /// 
>         cond(cummax_consumed[_n-1] > cummax_consumed & !missing(cummax_consumed[_n-1]), ///
>         cummax_consumed[_n-1], cummax_consumed[_n]) 
(152 real changes made)

. gen consumed_noadjust = cummax_consumed

. 
. * Only keep plants that had adjusted emissions and only keep emissions at the end of the 
. * period
. keep if consumed_noadjust != consumed
(4,963 observations deleted)

. gsort gpcb_id commodity_period date

. bysort gpcb_id commodity_period: gen last_record_of_period = (_n == _N)

. keep if last_record_of_period == 1
(115 observations deleted)

. 
. * A few formatting modifications to make things easier down the line
. gen period_num = 7

. rename consumed_noadjust emission_val_noadjust

. gen emission_val_noadjust_prorated = emission_val_noadjust * 30/31

. 
. keep gpcb_id period_num emission_val_noadjust_prorated

. 
. label var gpcb_id "Plant GPCB ID"

. label var period_num "Commodity period number"

. label var emission_val_noadjust "Validate total emissions (monthly pro-rated kg) -- No GPCB period VII adjustment"

. 
. label data "Period VII unadjusted emissions. See footnote 22 in the paper for details"

. save "$TRADING_DATA_CLEAN/panel_plant-period_unadjusted_emissions.dta", replace
(file 02DataPipeline/trading/cleaned/panel_plant-period_unadjusted_emissions.dta not found)
file 02DataPipeline/trading/cleaned/panel_plant-period_unadjusted_emissions.dta saved

. 
. restore 

.         
. save "$TRADING_DATA_OUT/inventory_plant-commodity-date.dta", replace
(file 02DataPipeline/trading/intermediate/inventory_plant-commodity-date.dta not found)
file 02DataPipeline/trading/intermediate/inventory_plant-commodity-date.dta saved

. 
. ********************************************************************************
. *** Aggregate to a plant-period panel
. ********************************************************************************
. 
. gsort gpcb_id commodity_period date

. bysort gpcb_id commodity_period: gen last_record_of_period = (_n == _N)

. keep if last_record_of_period == 1
(41,380 observations deleted)

. drop date last_record_of_period

. order gpcb_id commodity commodity_period allocated_quantity blocked sold purchased consumed current_inventory

. // save "$WORKING/NeML_inventory.dta", replace
. 
. * Merge gpcb_ids to keep only in-sample plants
. merge m:1 gpcb_id using "$TRADING_DATA_OUT/covariates_plant.dta", keepusing(gpcb_id)

    Result                      Number of obs
    -----------------------------------------
    Not matched                            81
        from master                        81  (_merge==1)
        from using                          0  (_merge==2)

    Matched                             1,560  (_merge==3)
    -----------------------------------------

. keep if _merge == 3
(81 observations deleted)

. drop _merge

. 
. * 156 plants x 10 commodity periods = 1560 obserations
. 
. rename blocked blocked_period

. rename sold sold_period

. rename purchased purchased_period

. rename consumed consumed_period

. rename current_inventory final_inventory_period

. save "$TRADING_DATA_OUT/inventory_plant-commodity.dta", replace
(file 02DataPipeline/trading/intermediate/inventory_plant-commodity.dta not found)
file 02DataPipeline/trading/intermediate/inventory_plant-commodity.dta saved

. 
. ********************************************************************************
. *** Check Inconsistency
. ********************************************************************************
. 
. use "$TRADING_DATA_OUT/inventory_plant-commodity.dta", clear

. gen my_final_inventory = allocated_quantity + purchased_period - sold_period - consumed_period

. sort commodity_period gpcb_id

. * br if my_final_inventory != final_inventory_period
. * 138 / 1560 plant-period observations are inconsistent.
. * All of them are PSUM010320 (commodity period 6).
. 
end of do-file

. do "$CODE_DIR/construct_datasets/clean_trading_data.do"

. /************************************************************************
> Purpose:        Create a plant-day NeML trading-inventory data set.
> 
> Notes:      The final product is a plant-day NeML trading-inventory data set 
>                         (N=10,702) with following columns:
>                         * gpcb_id: plant unique id
>                         * commodity: commodity unique id
>                         * date: date
>                         * bid_id: bid unique id
>                         * bid_status: bid status
>                                 * FILL: filled
>                                 * PFILL: partially filled
>                                 * CNL/CNLS: canceled
>                                 * REJ: rejected
>                         * bid_price: bid price (Rs/kg)
>                         * bid_qty: bid quantity (kg)
>                         * bid_value = bid_price * bid_qty (Rs)
>                         * trade_price: trade price (Rs/kg)
>                         * trade_qty: trade quantity (kg)
>                         * trade_qty_cum: cumulative trade quantity (kg)
>                         * trade_value = trade_price * trade_qty (Rs)
>                         * allocated_quantity: initial permit allocation (kg)
>                         * permit_holding = allocated_quantity + trade_qty_cum (kg)
>                         * consumed: validated emissions in a period (kg)
>                         * current_inventory: permits left by the end of a period (kg)
>                         * sold: permits sold in a period (kg)
>                         * purchase: permits purchased in a period (kg)
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. ********************************************************************************
. *** Clean NeML order-trade record
. ********************************************************************************
. 
. import delimited "$TRADING_DATA_IN/NeMLordertrade_Sept2019-Mar2021.csv", clear
(11 vars, 10,625 obs)

. tostring bid_id, replace format(%17.0g)
bid_id was double now str14

. 
. gen mydate = date(date,"YMD") 

. sort mydate gpcb_id

. drop date 

. rename mydate date

. format date %tddd-Mon-CCYY

. 
. ********************************************************************************
. *** Merge plant-period NeML Inventory data set
. ********************************************************************************
. 
. drop if gpcb_id == 158777056
(0 observations deleted)

. destring gpcb_id, replace
gpcb_id already numeric; no replace

. merge m:1 gpcb_id commodity using "$TRADING_DATA_OUT/inventory_plant-commodity.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                           255
        from master                        89  (_merge==1)
        from using                        166  (_merge==2)

    Matched                            10,536  (_merge==3)
    -----------------------------------------

. * Dropping 4 observations from GPCBID 21320
. drop if _merge == 1
(89 observations deleted)

. drop _merge

. 
. rename status bid_status

. sort gpcb_id commodity_period date bid_id

. bysort gpcb_id commodity_period: gen trade_qty_cum = sum(trade_qty)

. gen permit_holding = allocated_quantity + trade_qty_cum

. 
. sort gpcb_id commodity_period date bid_id

. order gpcb_id commodity commodity_period date bid_id bid_status bid_price bid_qty bid_value trade_price trade_qty trade_qty_cum trade_value permit_holding allocated_quantity consumed_period final_inventory_period

. 
. * 10,702 (plant, commodity, date, bid) observations
. 
. label var gpcb_id "Plant GPCB ID"

. label var commodity "Commodity ID"

. label var date "Bid date"

. label var bid_id "Bid ID"

. label var bid_status "Bid status (REJ=rejected, CNLS=cancelled, FILL=filled)"

. label var bid_price "Bid price (Rs/kg)"

. label var bid_qty "Bid quantity (kg)"

. label var bid_value "Bid value (Rs) = bid_qty * bid_price"

. label var trade_price "Trade price (Rs/kg)"

. label var trade_qty "Trade quantity (kg)"

. label var trade_qty_cum "Trade quantity cumulative (kg)"

. label var trade_value "Trade value (Rs) = trade_qty * trade_price"

. label var permit_holding "Permit holdings (kg) = initial allocation + cumulative trade quantity " 

. 
. save "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta", replace
(file 02DataPipeline/trading/intermediate/record_plant-commodity-date-bid.dta not found)
file 02DataPipeline/trading/intermediate/record_plant-commodity-date-bid.dta saved

. 
. ********************************************************************************
. *** Check inconsistency
. ********************************************************************************
. 
. use "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta", clear

. 
. ** 1) Check whether trade quantity = order quantity for full quantity order (FILL)
. // br if trade_qty != bid_qty & bid_status == "FILL"
. 
. * 7 inconsistent records
. 
. // gpcb_id      commodity       bid_id
. // 20579        PSUM010220      10661117340004
. // 20820        PSUM010220      10661147590015
. // 21184        PSUM161019      13171414020014
. // 21335        PSUM010220      10661114390002
. // 21387        PSUM010220      10661119540005
. // 21486        PSUM010220      10661100410001
. // 27688        PSUM010220      10661117320003
. 
. ** 2) Check whether trade data and inventory data matches
. 
. preserve

. 
. replace trade_qty = 0 if missing(trade_qty)
(6,903 real changes made)

. 
. * Create total purchase based on trade record
. bysort gpcb_id commodity_period: egen total_purchased = sum(trade_qty) if trade_qty > 0
(8,675 missing values generated)

. bysort gpcb_id commodity_period: egen my_purchased = mean(total_purchased)
(2,651 missing values generated)

. drop total_purchased

. replace my_purchased = 0 if missing(my_purchased)
(2,651 real changes made)

. 
. * Create total sale based on trade record
. bysort gpcb_id commodity_period: egen total_sold = sum(trade_qty) if trade_qty < 0
(8,930 missing values generated)

. bysort gpcb_id commodity_period: egen my_sold = mean(total_sold)
(2,489 missing values generated)

. drop total_sold

. replace my_sold = 0 if missing(my_sold)
(2,489 real changes made)

. replace my_sold = -my_sold
(8,213 real changes made)

. 
. * Generate inventory using purchase and sale from trade record
. gen my_final_inventory = allocated_quantity + my_purchased - my_sold - consumed

. 
. * Collapse to plant-period level
. keep gpcb_id commodity commodity_period purchased_period my_purchased sold_period my_sold final_inventory_period my_final_inventory

. order gpcb_id commodity commodity_period purchased_period my_purchased sold_period my_sold final_inventory_period my_final_inventory

. duplicates drop

Duplicates in terms of all variables

(9,142 observations deleted)

. 
. * Check if purchase/sale/inventory match
. sort commodity_period gpcb_id

. keep if (purchased_period != my_purchased) | (sold_period != my_sold) | (final_inventory_period != my_final_inventory)
(1,335 observations deleted)

. * 225 / 1560 plant-commodity observations are inconsistent.
. 
. rename commodity_period period

. tab period

  Commodity |
     period |
     number |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |          5        2.22        2.22
          2 |         13        5.78        8.00
          3 |         32       14.22       22.22
          4 |          5        2.22       24.44
          5 |         12        5.33       29.78
          6 |        138       61.33       91.11
          7 |          5        2.22       93.33
          8 |          5        2.22       95.56
          9 |          5        2.22       97.78
         10 |          5        2.22      100.00
------------+-----------------------------------
      Total |        225      100.00

. //      period |      Freq.     Percent        Cum.
. // ------------+-----------------------------------
. //           1 |          5        2.22        2.22
. //           2 |         13        5.78        8.00
. //           3 |         32       14.22       22.22
. //           4 |          5        2.22       24.44
. //           5 |         12        5.33       29.78
. //           6 |        138       61.33       91.11
. //           7 |          5        2.22       93.33
. //           8 |          5        2.22       95.56
. //           9 |          5        2.22       97.78
. //          10 |          5        2.22      100.00
. // ------------+-----------------------------------
. //       Total |        225      100.00
. 
. drop if period == 6
(138 observations deleted)

. tab gpcb_id

 Plant GPCB |
         ID |      Freq.     Percent        Cum.
------------+-----------------------------------
   1.01e+08 |          9       10.34       10.34
   1.02e+08 |          1        1.15       11.49
   1.02e+08 |          2        2.30       13.79
   1.02e+08 |          1        1.15       14.94
   1.02e+08 |          1        1.15       16.09
   1.03e+08 |          1        1.15       17.24
   1.03e+08 |          1        1.15       18.39
   1.03e+08 |          2        2.30       20.69
   1.03e+08 |          9       10.34       31.03
   1.03e+08 |          9       10.34       41.38
   1.03e+08 |          9       10.34       51.72
   1.04e+08 |          9       10.34       62.07
   1.04e+08 |          1        1.15       63.22
   1.05e+08 |          1        1.15       64.37
   1.05e+08 |          1        1.15       65.52
   1.05e+08 |          1        1.15       66.67
   1.05e+08 |          1        1.15       67.82
   1.05e+08 |          1        1.15       68.97
   1.06e+08 |          1        1.15       70.11
   1.06e+08 |          2        2.30       72.41
   1.06e+08 |          1        1.15       73.56
   1.06e+08 |          1        1.15       74.71
   1.08e+08 |          1        1.15       75.86
   1.08e+08 |          1        1.15       77.01
   1.08e+08 |          1        1.15       78.16
   1.09e+08 |          1        1.15       79.31
   1.10e+08 |          1        1.15       80.46
   1.11e+08 |          1        1.15       81.61
   1.12e+08 |          1        1.15       82.76
   1.12e+08 |          2        2.30       85.06
   1.12e+08 |          1        1.15       86.21
   1.12e+08 |          1        1.15       87.36
   1.13e+08 |          1        1.15       88.51
   1.13e+08 |          1        1.15       89.66
   1.13e+08 |          1        1.15       90.80
   1.14e+08 |          2        2.30       93.10
   1.14e+08 |          1        1.15       94.25
   1.14e+08 |          1        1.15       95.40
   1.14e+08 |          1        1.15       96.55
   1.15e+08 |          1        1.15       97.70
   1.15e+08 |          1        1.15       98.85
   1.15e+08 |          1        1.15      100.00
------------+-----------------------------------
      Total |         87      100.00

. //     gpcb_id |      Freq.     Percent        Cum.
. // ------------+-----------------------------------
. //       13916 |          9       10.34       10.34
. //       20488 |          1        1.15       11.49
. //       20490 |          2        2.30       13.79
. //       20525 |          1        1.15       14.94
. //       20546 |          1        1.15       16.09
. //       20579 |          1        1.15       17.24
. //       20583 |          1        1.15       18.39
. //       20623 |          2        2.30       20.69
. //       20632 |          9       10.34       31.03
. //       20633 |          9       10.34       41.38
. //       20635 |          9       10.34       51.72
. //       20685 |          9       10.34       62.07
. //       20765 |          1        1.15       63.22
. //       20820 |          1        1.15       64.37
. //       20825 |          1        1.15       65.52
. //       20826 |          1        1.15       66.67
. //       20848 |          1        1.15       67.82
. //       20869 |          1        1.15       68.97
. //       20870 |          1        1.15       70.11
. //       20880 |          2        2.30       72.41
. //       20889 |          1        1.15       73.56
. //       20935 |          1        1.15       74.71
. //       21025 |          1        1.15       75.86
. //       21033 |          1        1.15       77.01
. //       21038 |          1        1.15       78.16
. //       21122 |          1        1.15       79.31
. //       21203 |          1        1.15       80.46
. //       21260 |          1        1.15       81.61
. //       21310 |          1        1.15       82.76
. //       21334 |          2        2.30       85.06
. //       21335 |          1        1.15       86.21
. //       21387 |          1        1.15       87.36
. //       21446 |          1        1.15       88.51
. //       21457 |          1        1.15       89.66
. //       21479 |          1        1.15       90.80
. //       21486 |          2        2.30       93.10
. //       21520 |          1        1.15       94.25
. //       24939 |          1        1.15       95.40
. //       27688 |          1        1.15       96.55
. //       28161 |          1        1.15       97.70
. //       32072 |          1        1.15       98.85
. //       33830 |          1        1.15      100.00
. // ------------+-----------------------------------
. //       Total |         87      100.00
. 
. restore

. 
end of do-file

. do "$CODE_DIR/construct_datasets/define_periods.do"

. /************************************************************************
> Notes:      The final products are a day-period data set (N=357) 
>                         with following columns:
>                         * date: date
>                         * commodity: unique commodity id
>                         * compliance_period: compliance period number (1-10)
>                         * commodity_period: commodity period number (1-10)
>                         * trueup_period: trueup period number (0 if not between a trueup period)
>                         * compliance_start: start date of a compliance period
>                         * compliance_end: end date of a compliance period
>                         * compliance_length: length of a compliance period
>                         * commodity_start: start date of a commodity period
>                         * commodity_end: end date of a commodity period
>                         * commodity_length: length of a commodity period
>                         * complinace_month_cap: cap (per 30 days)
>                         * compliance_cap: complinace_month_cap / 30 * compliance_length
>                         * trade_length: days between compliance_start and commodity_end
>                         
>                         and a period data set (N=10) with following columns:
>                         * period: period number
>                         * period_start: start date of the compliance period 
>                         * period_end: end date of the commodity period
>                         * period_length: number of days between period_start and period_end
>                         * compliance_end: end date of the compliance period
>                         * compliance_length: number of days between period_start and compliance_end
> *************************************************************************/
. 
. ********************************************************************************
. *** Generate Date-Period Data 
. ********************************************************************************
. 
. set more off

. clear all

. pause on

. 
. local start_date = date("2019/07/16", "YMD")

. local end_date = date("2021/03/31", "YMD")

. set obs `=`end_date'-`start_date'+1'
Number of observations (_N) was 0, now 625.

. egen date = seq(), from(`start_date') to(`end_date')

. format %td date

. format date %tddd-Mon-CCYY

. 
. merge 1:m date using "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta"
(variable date was int, now float to accommodate using data's values)

    Result                      Number of obs
    -----------------------------------------
    Not matched                           914
        from master                       374  (_merge==1)
        from using                        540  (_merge==2)

    Matched                            10,162  (_merge==3)
    -----------------------------------------

. keep date commodity commodity_period

. duplicates drop

Duplicates in terms of all variables

(10,407 observations deleted)

. keep if !missing(date)
(10 observations deleted)

. sort date

. 
. ********************************************************************************
. ** Define Commodity Period 
. ********************************************************************************
. 
. preserve

. bysort commodity: egen date_min = min(date)

. bysort commodity: egen date_max = max(date)

. format date_min %td

. format date_max %td

. keep commodity commodity_period date_min date_max

. duplicates drop

Duplicates in terms of all variables

(648 observations deleted)

. drop if missing(commodity)
(1 observation deleted)

. reshape long date, i(commodity) j(range) string
(j = _max _min)

Data                               Wide   ->   Long
-----------------------------------------------------------------------------
Number of observations               10   ->   20          
Number of variables                   4   ->   4           
j variable (2 values)                     ->   range
xij variables:
                      date_max date_min   ->   date
-----------------------------------------------------------------------------

. sort date

. drop range

. xtset commodity_period date, delta(1 day)

Panel variable: commodity_period (weakly balanced)
 Time variable: date, 17sep2019 to 08apr2021, but with gaps
         Delta: 1 day

. tsfill

. bysort commodity_period: replace commodity = commodity[1]
(531 real changes made)

. tempfile commodity_df

. save `commodity_df'
file /var/folders/7r/1zsrb09s0r578bq3nysvhzd40000gn/T//St40195.000002 saved as .dta format

. restore

. 
. drop commodity commodity_period

. duplicates drop

Duplicates in terms of all variables

(28 observations deleted)

. merge 1:m date using `commodity_df'

    Result                      Number of obs
    -----------------------------------------
    Not matched                           117
        from master                       115  (_merge==1)
        from using                          2  (_merge==2)

    Matched                               549  (_merge==3)
    -----------------------------------------

. drop _merge

. drop if date > td(08apr2021)
(0 observations deleted)

. 
. * Mock
. drop if date < td(16sep2019)
(62 observations deleted)

. * Interregnum-I
. drop if date > td(26mar2020) & date < td(08oct2020) 
(195 observations deleted)

. * Interregnum-II
. drop if date > td(09oct2020) & date < td(01dec2020)
(52 observations deleted)

. 
. bysort commodity: egen commodity_start = min(date)

. bysort commodity: egen commodity_end = max(date)

. replace commodity_start = . if missing(commodity)
(1 real change made, 1 to missing)

. replace commodity_end = . if missing(commodity)
(1 real change made, 1 to missing)

. format commodity_start %tddd-Mon-CCYY

. format commodity_end %tddd-Mon-CCYY

. sort date commodity_period

. 
. * 357 (day, commodity) observations from 16-Sep-2019 to 8-Apr-2021 
. * (excluding interregnums)
. 
. ********************************************************************************
. ** Define Compliance Period 
. ********************************************************************************
. 
. gen compliance_start = 0

. gen compliance_end = 0

. gen compliance_period = 0

. gen compliance_month_cap = 0

. format compliance_start %tddd-Mon-CCYY

. format compliance_end %tddd-Mon-CCYY

. 
. ** Mock-I
. local date_start = td(15jul2019)

. local date_end = td(13aug2019) 

. replace compliance_start = `date_start' if date >= `date_start' 
(357 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(357 real changes made)

. replace compliance_month_cap = 280000 if date >= `date_start' 
(357 real changes made)

. ** Mock-II
. local date_start = `date_end'

. local date_end = td(16sep2019)

. replace compliance_start = `date_start' if date >= `date_start' 
(357 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(357 real changes made)

. ** Comp-I
. local date_start = `date_end'

. local date_end = td(16oct2019)

. replace compliance_start = `date_start' if date >= `date_start' 
(357 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(357 real changes made)

. replace compliance_period = 1 if date >= `date_start' 
(357 real changes made)

. ** Comp-II
. local date_start = `date_end'

. local date_end = td(16nov2019)

. replace compliance_start = `date_start' if date >= `date_start' 
(327 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(327 real changes made)

. replace compliance_period = 2 if date >= `date_start' 
(327 real changes made)

. replace compliance_month_cap = 200000 if date >= `date_start' 
(327 real changes made)

. ** Comp-III
. local date_start = `date_end'

. local date_end = td(01jan2020)

. replace compliance_start = `date_start' if date >= `date_start' 
(295 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(295 real changes made)

. replace compliance_period = 3 if date >= `date_start' 
(295 real changes made)

. replace compliance_month_cap = 180000 if date >= `date_start' 
(295 real changes made)

. ** Comp-IV
. local date_start = `date_end'

. local date_end = td(01feb2020)

. replace compliance_start = `date_start' if date >= `date_start' 
(245 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(245 real changes made)

. replace compliance_period = 4 if date >= `date_start' 
(245 real changes made)

. replace compliance_month_cap = 170000 if date >= `date_start' 
(245 real changes made)

. ** Comp-V
. local date_start = `date_end'

. local date_end = td(01mar2020)

. replace compliance_start = `date_start' if date >= `date_start' 
(212 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(212 real changes made)

. replace compliance_period = 5 if date >= `date_start'
(212 real changes made)

. ** Comp-VI
. local date_start = `date_end'

. local date_end = td(22mar2020)

. replace compliance_start = `date_start' if date >= `date_start' 
(179 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(179 real changes made)

. replace compliance_period = 6 if date >= `date_start' 
(179 real changes made)

. ** Interregnum-I
. local date_start = `date_end'

. local date_end = td(12oct2020)

. replace compliance_start = `date_start' if date >= `date_start' 
(153 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(153 real changes made)

. replace compliance_period = 0 if date >= `date_start' 
(153 real changes made)

. ** Mock-III
. local date_start = `date_end'

. local date_end = td(12nov2020)

. replace compliance_start = `date_start' if date >= `date_start' 
(146 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(146 real changes made)

. replace compliance_period = 0 if date >= `date_start' 
(0 real changes made)

. ** Interregnum-II
. local date_start = `date_end'

. local date_end = td(01dec2020)

. replace compliance_start = `date_start' if date >= `date_start' 
(146 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(146 real changes made)

. replace compliance_period = 0 if date >= `date_start' 
(0 real changes made)

. ** Comp-VII
. local date_start = `date_end'

. local date_end = td(01jan2021)

. replace compliance_start = `date_start' if date >= `date_start' 
(146 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(146 real changes made)

. replace compliance_period = 7 if date >= `date_start' 
(146 real changes made)

. ** Comp-VIII
. local date_start = `date_end'

. local date_end = td(01feb2021)

. replace compliance_start = `date_start' if date >= `date_start' 
(115 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(115 real changes made)

. replace compliance_period = 8 if date >= `date_start' 
(115 real changes made)

. ** Comp-IX
. local date_start = `date_end'

. local date_end = td(01mar2021)

. replace compliance_start = `date_start' if date >= `date_start' 
(81 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(81 real changes made)

. replace compliance_period = 9 if date >= `date_start' 
(81 real changes made)

. ** Comp-X
. local date_start = `date_end'

. local date_end = td(01apr2021)

. replace compliance_start = `date_start' if date >= `date_start' 
(46 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(46 real changes made)

. replace compliance_period = 10 if date >= `date_start' 
(46 real changes made)

. ** Comp-XI
. local date_start = `date_end'

. local date_end = td(01may2021)

. replace compliance_start = `date_start' if date >= `date_start' 
(8 real changes made)

. replace compliance_end = `date_end' - 1 if date >= `date_start' 
(8 real changes made)

. replace compliance_period = 11 if date >= `date_start' 
(8 real changes made)

. 
. gen compliance_length = (compliance_end - compliance_start) + 1

. gen compliance_cap = compliance_month_cap * compliance_length / 30

. 
. drop if compliance_period == 0 & missing(commodity_period)
(0 observations deleted)

. sort date commodity

. 
. * 357 (day, commodity) observations from 16-Sep-2019 to 8-Apr-2021 
. * (excluding interregnums)
. 
. ********************************************************************************
. ** Define True-up Period 
. ********************************************************************************
. 
. gen trueup_period = 0

. replace trueup_period = commodity_period if commodity_period + 1 == compliance_period
(67 real changes made)

. replace trueup_period = 6 if commodity_period == 6 & compliance_period == 0
(7 real changes made)

. 
. gen trade_length = 0

. forval i = 1/10 {
  2.         
.         preserve
  3.         keep if compliance_period == `i' | trueup_period == `i'
  4.         keep date 
  5.         duplicates drop
  6.         sum date
  7.         local trade_days = r(N)
  8.         restore 
  9. 
.         replace trade_length = `trade_days' if commodity_period == `i'
 10. }
(320 observations deleted)

Duplicates in terms of all variables

(0 observations are duplicates)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         37       21826    10.82436      21808      21844
(36 real changes made)
(318 observations deleted)

Duplicates in terms of all variables

(1 observation deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         38     21856.5    11.11306      21838      21875
(32 real changes made)
(299 observations deleted)

Duplicates in terms of all variables

(4 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         54     21895.5    15.73213      21869      21922
(51 real changes made)
(317 observations deleted)

Duplicates in terms of all variables

(2 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         38     21933.5    11.11306      21915      21952
(32 real changes made)
(317 observations deleted)

Duplicates in terms of all variables

(4 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         36     21963.5    10.53565      21946      21981
(33 real changes made)
(324 observations deleted)

Duplicates in terms of all variables

(5 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         28    22002.43     55.3055      21975      22197
(26 real changes made)
(319 observations deleted)

Duplicates in terms of all variables

(0 observations are duplicates)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         38     22268.5    11.11306      22250      22287
(38 real changes made)
(315 observations deleted)

Duplicates in terms of all variables

(3 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         39       22300    11.40175      22281      22319
(35 real changes made)
(314 observations deleted)

Duplicates in terms of all variables

(7 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         36     22329.5    10.53565      22312      22347
(35 real changes made)
(311 observations deleted)

Duplicates in terms of all variables

(7 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        date |         39       22359    11.40175      22340      22378
(38 real changes made)

. 
. order date commodity compliance_period commodity_period trueup_period compliance_start compliance_end compliance_length compliance_month_cap compliance_cap commodity_start commodity_end trade_length

. 
. 
. label var date "Date"

. label var commodity "Commodity ID"

. label var compliance_period "Compliance period number"

. label var commodity_period "Commodity period number"

. label var trueup_period "True-up period number (0 if not in True-up period)"

. label var compliance_start "Compliance period start date"

. label var compliance_end "Compliance period end date"

. label var compliance_length "Length of compliance period (days)"

. label var compliance_month_cap "Complinace period monthly cap (kg / 30 days)"

. label var compliance_cap "Compliance period actual cap = (compliance_month_cap / 30) * compliance_length"

. label var commodity_start "First date of trading record in the commodity period"

. label var commodity_end "Last date of trading record in the commodity period"

. label var trade_length "Compliance + true-up period length"

. 
. * 357 (date, period) observations from 16-Sep-2019 to 8-Apr-2021.
. save "$TRADING_DATA_OUT/index_day-commodity-period.dta", replace
(file 02DataPipeline/trading/intermediate/index_day-commodity-period.dta not found)
file 02DataPipeline/trading/intermediate/index_day-commodity-period.dta saved

. 
. 
. preserve

. keep date commodity commodity_period compliance_start compliance_end commodity_end

. rename commodity_period period

. rename compliance_start period_start

. rename compliance_end period_end_compliance

. rename commodity_end period_end_commodity

. replace commodity = "PSUM160919" if date == td(16sep2019)
(1 real change made)

. replace period = 1 if date == td(16sep2019)
(1 real change made)

. replace period_end_commodity = td(22oct2019) if date == td(16sep2019)
(1 real change made)

. cross using "$TRADING_DATA_OUT/index_plant.dta"

. order gpcb_id

. save "$TRADING_DATA_OUT/index_plant-date-period.dta", replace
(file 02DataPipeline/trading/intermediate/index_plant-date-period.dta not found)
file 02DataPipeline/trading/intermediate/index_plant-date-period.dta saved

. * 156 plants x 357 (date, period) = 55,692 (plant, date, period) obs.
. restore

. 
. ********************************************************************************
. ** Generate Period Data
. ********************************************************************************
. 
. keep if compliance_period == commodity_period
(75 observations deleted)

. rename compliance_period period

. gen period_start = compliance_start

. format period_start %tddd-Mon-CCYY

. label var period_start "Compliance period start date"

. rename compliance_end period_end_compliance

. rename commodity_end period_end_commodity

. rename trade_length period_length 

. 
. keep period period_start period_end_compliance period_length period_end_commodity compliance_length compliance_month_cap compliance_cap

. order period period_start period_end_compliance period_end_commodity period_length compliance_length compliance_month_cap compliance_cap

. duplicates drop

Duplicates in terms of all variables

(272 observations deleted)

. save "$TRADING_DATA_OUT/index_period.dta", replace
(file 02DataPipeline/trading/intermediate/index_period.dta not found)
file 02DataPipeline/trading/intermediate/index_period.dta saved

. 
. ********************************************************************************
. ** Add Bid Day Variable to Trading Record
. ********************************************************************************
. 
. use "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta", replace

. 
. *** create bid day variable
. rename commodity_period period

. merge m:1 period using "$TRADING_DATA_OUT/index_period.dta", keepusing(period_start period_length period_end_commodity)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            10,702  (_merge==3)
    -----------------------------------------

. drop _merge

. gen bid_day = date - period_start + 1
(166 missing values generated)

. replace bid_day = period_length - (period_end_commodity - date) if bid_day > period_length
(60 real changes made)

. gen bid_day_norm = bid_day / period_length
(166 missing values generated)

. rename period commodity_period

. drop period_start period_end_commodity period_length

. 
. order bid_day bid_day_norm, after(bid_status)

. label var bid_day "Number of day when the bid is placed in a period"

. label var bid_day_norm "Bid day normalized = bid day / period length"

. sort gpcb_id commodity_period date bid_id

. 
. save "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta", replace
file 02DataPipeline/trading/intermediate/record_plant-commodity-date-bid.dta saved

. 
end of do-file

. do "$CODE_DIR/construct_datasets/check_consistency.do"

. /************************************************************************
> Author:         Kaixin Wang
> Project:        ETS
> Purpose:        Check consistency between inventory and trading data
> 
> Date created:   30 March 2022
> Version:                STATA 17 MP
> 
> Last edited:    10 June 2022
> Edited by:              Kaixin  
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. ********************************************************************************
. *** Check NeML inventory daily data
. ********************************************************************************
. 
. use "$TRADING_DATA_OUT/inventory_plant-commodity-date.dta", replace

. merge m:1 gpcb_id using "$TRADING_DATA_OUT/index_plant.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                         2,149
        from master                     2,149  (_merge==1)
        from using                          0  (_merge==2)

    Matched                            40,872  (_merge==3)
    -----------------------------------------

. keep if _merge == 3
(2,149 observations deleted)

. drop _merge 

. 
. order date commodity gpcb_id allocated_quantity purchased sold consumed current_inventory

. sort date commodity gpcb_id

. 
. preserve

. keep if allocated_quantity + purchased - sold - consumed != current_inventory
(40,595 observations deleted)

. export excel using "$TRADING_DATA_OUT/inventory_to_check.xlsx", firstrow(variables) replace
file 02DataPipeline/trading/intermediate/inventory_to_check.xlsx saved

. restore

. 
. ********************************************************************************
. *** Check consistency between daily inventory and daily trading data
. ********************************************************************************
. 
. * prepare daily inventory-trading data set
. 
. use "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta", replace

. drop purchased_period sold_period consumed_period blocked_period final_inventory_period trade_qty_cum permit_holding allocated_quantity

. drop if trade_qty == .
(6,903 observations deleted)

. keep gpcb_id commodity date commodity_period trade_qty

. gen purchase_qty = 0

. gen sale_qty = 0

. replace purchase_qty = trade_qty if trade_qty > 0
(2,027 real changes made)

. replace sale_qty = -trade_qty if trade_qty < 0
(1,772 real changes made)

. collapse (sum) purchase_qty sale_qty, by(gpcb_id commodity commodity_period date)

. 
. merge 1:1 gpcb_id commodity date using "$TRADING_DATA_OUT/inventory_plant-commodity-date.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                        39,950
        from master                       106  (_merge==1)
        from using                     39,844  (_merge==2)

    Matched                             3,177  (_merge==3)
    -----------------------------------------

. sort gpcb_id commodity_period date

. drop _merge

. 
. merge m:1 gpcb_id using "$TRADING_DATA_OUT/index_plant.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                         2,149
        from master                     2,149  (_merge==1)
        from using                          0  (_merge==2)

    Matched                            40,978  (_merge==3)
    -----------------------------------------

. keep if _merge == 3
(2,149 observations deleted)

. drop _merge 

. 
. sort gpcb_id commodity_period date

. replace purchase_qty = 0 if missing(purchase_qty)
(37,695 real changes made)

. replace sale_qty = 0 if missing(sale_qty)
(37,695 real changes made)

. by gpcb_id commodity_period: gen purchase_qty_cum = sum(purchase_qty)

. by gpcb_id commodity_period: gen sale_qty_cum = sum(sale_qty)

. 
. order gpcb_id commodity commodity_period date purchase_qty sale_qty allocated_quantity purchase_qty_cum purchased sale_qty_cum sold consumed current_inventory

. 
. * flag inconsistencies
. 
. gen is_consistent = 1

. replace is_consistent = 0 if purchase_qty_cum != purchased
(753 real changes made)

. replace is_consistent = 0 if sale_qty_cum != sold
(233 real changes made)

. 
. tab is_consistent

is_consiste |
         nt |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        986        2.41        2.41
          1 |     39,992       97.59      100.00
------------+-----------------------------------
      Total |     40,978      100.00

. // is_consiste |
. //          nt |      Freq.     Percent        Cum.
. // ------------+-----------------------------------
. //           0 |        986        2.41        2.41
. //           1 |     39,992       97.59      100.00
. // ------------+-----------------------------------
. //       Total |     40,978      100.00
. 
. 
. * Errors might be carried over to rest of the period.
. * We figure out the first instance of each inconsistency.
. 
. by gpcb_id commodity_period: gen final_day = (_n == _N)

. 
. gen inconsistent_period = 0

. replace inconsistent_period = 1 if final_day == 1 & is_consistent == 0
(89 real changes made)

. by gpcb_id commodity_period: egen sum_inconsistent_period = sum(inconsistent_period)

. drop inconsistent_period final_day

. rename sum_inconsistent_period inconsistent_period

. 
. keep if inconsistent_period == 1
(38,346 observations deleted)

. 
. foreach var of varlist*{
  2.         
.         if !inlist("`var'","gpcb_id","commodity","commodity_period","date","pruchase_qty","sale_qty"){
  3.                 gen dif_`var' = abs(`var'[_n]-`var'[_n-1])
  4.                 replace dif_`var' = 0 if missing(dif_`var')
  5.         }
  6.         
. }
(1 missing value generated)
(1 real change made)
(7 missing values generated)
(7 real changes made)
(1 missing value generated)
(1 real change made)
(7 missing values generated)
(7 real changes made)
(1 missing value generated)
(1 real change made)
(7 missing values generated)
(7 real changes made)
(7 missing values generated)
(7 real changes made)
(7 missing values generated)
(7 real changes made)
(7 missing values generated)
(7 real changes made)
(1 missing value generated)
(1 real change made)
(1 missing value generated)
(1 real change made)

. 
. egen group = group(gpcb_id commodity)

. gen dif_group = group[_n]-group[_n-1]
(1 missing value generated)

. replace dif_group = 1 if missing(dif_group)
(1 real change made)

. 
. egen dif = rowtotal(dif*)

. drop if dif == 0
(1,798 observations deleted)

. drop dif* group inconsistent_period

. 
. // keep gpcb_id commodity commodity_period
. // duplicates drop
. // tab gpcb_id
. // pause
. 
end of do-file

. 
. ** Construct cleaned data sets for analysis
. do "$CODE_DIR/construct_datasets/construct_panel_plant-period-date-bid.do"

. /************************************************************************
> Purpose:        Create Plant-Period-Date-Bid Panel
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. use "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta", clear

. 
. rename commodity_period period

. merge m:1 period using "$TRADING_DATA_OUT/index_period.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            10,702  (_merge==3)
    -----------------------------------------

. drop _merge

. drop if missing(bid_id)
(166 observations deleted)

. sort gpcb_id period date bid_id

. 
. ** generate plant x period index for plant x period FEs
. egen plant_period_id = group(gpcb_id period)

. 
. ********************************************************************************
. *** Delete rejected bids, and create relevant variables for analysis
. ********************************************************************************
. 
. drop if bid_status == "REJ"
(2,079 observations deleted)

. drop if missing(bid_qty)
(24 observations deleted)

. 
. ** Generate auction indicator
. gen week_days = dow(date)

. bysort commodity date: egen min_bid_price = min(bid_price)

. bysort commodity date: egen max_bid_price = max(bid_price)

. gen is_auction = 0

. replace is_auction = 1 if min_bid_price != max_bid_price
(3,099 real changes made)

. replace is_auction = 0 if date == td(08jan2020) & commodity == "PSUM161119"
(129 real changes made)

. replace is_auction = 0 if date == td(07feb2020) & commodity == "PSUM010120"
(97 real changes made)

. replace is_auction = 0 if date == td(07mar2020) & commodity == "PSUM010220"
(77 real changes made)

. drop min_bid_price max_bid_price

. label var is_auction "=1 if placed on an auction day" 

. 
. // tab is_auction
. //   Auction=1 |      Freq.     Percent        Cum.
. // ------------+-----------------------------------
. //           0 |      5,637       66.84       66.84
. //           1 |      2,796       33.16      100.00
. // ------------+-----------------------------------
. //       Total |      8,433      100.00
. 
. 
. ** Generate week variables
. gen bid_day_temp = mod(bid_day, 7) - 1

. gen first_day_week = mod(week_days - bid_day_temp, 7)

. gen week_num = floor((bid_day + first_day_week - 1) / 7) + 1

. gen week_day_num =  week_num + (week_days - 1) / 7 

. bysort period: egen max_week_num = max(week_num)

. gen week_left = max_week_num - week_num

. drop bid_day_temp first_day_week week_days

. label var week_num "Number of weeks the bid is placed in the period"

. label var week_day_num "=week_num + (date - 1) / 7 (Monday is the first day of week)"

. label var max_week_num "Number of weeks in the period"

. label var week_left "Number of weeks left until the period ends."

. 
. ** Generate permit holdings if a bid is executed
. gen permit_holding_hyp = permit_holding

. replace permit_holding_hyp = permit_holding_hyp + bid_qty if missing(trade_qty)
(4,658 real changes made)

. replace permit_holding_hyp = permit_holding_hyp + bid_qty - trade_qty if !missing(trade_qty) & !missing(bid_qty) 
(655 real changes made)

. label var permit_holding_hyp "Permit holdings if a bid is executed (kg)"

. 
. ** Generate log variables
. gen ln_permit_holding_hyp = ln(permit_holding_hyp)
(9 missing values generated)

. gen ln_bid_price = ln(bid_price)

. label var ln_permit_holding_hyp "log[permit_holding_hyp (kg)]"

. label var ln_bid_price "log[bid_price (Rs)]"

. 
. sort gpcb_id period date bid_id

. 
. ********************************************************************************
. *** Merge baseline covariates
. ********************************************************************************
. merge m:1 gpcb_id using "$TRADING_DATA_OUT/covariates_plant.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             3
        from master                         0  (_merge==1)
        from using                          3  (_merge==2)

    Matched                             8,433  (_merge==3)
    -----------------------------------------

. drop _merge

. sort gpcb_id period date bid_id

. 
. 
. ********************************************************************************
. *** Merge potential max emissions for abatement costs panel
. ********************************************************************************
. merge m:1 gpcb_id using "$EMISSIONS_DATA_OUT/potential_max_emissions.dta", ///
>         keepusing(AverageUncontrolledMass12 AverageUncontrolledMass16) assert(2 3) keep(3) nogen

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                             8,436  
    -----------------------------------------

. rename AverageUncontrolledMass12 pm_mass_potential_max_12

. rename AverageUncontrolledMass16 pm_mass_potential_max_16

. 
. save "$TRADING_DATA_CLEAN/panel_plant-period-date-bid.dta", replace
(file 02DataPipeline/trading/cleaned/panel_plant-period-date-bid.dta not found)
file 02DataPipeline/trading/cleaned/panel_plant-period-date-bid.dta saved

. 
end of do-file

. do "$CODE_DIR/construct_datasets/construct_panel_plant-period-date.do"

. /************************************************************************
> Purpose:        Create Plant-Period-Date Panel
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. use "$TRADING_DATA_OUT/record_plant-commodity-date-bid.dta", clear

. drop if bid_status == "REJ"
(2,079 observations deleted)

. 
. foreach var of varlist bid_qty bid_value trade_qty trade_value{
  2.         bysort gpcb_id commodity date: egen temp = sum(`var') if `var' > 0 & !missing(`var')
  3.         bysort gpcb_id commodity date: egen buy_`var'_daily_sum = mean(temp)
  4.         drop temp
  5.         bysort gpcb_id commodity date: egen temp = sum(`var') if `var' < 0 & !missing(`var')
  6.         bysort gpcb_id commodity date: egen sell_`var'_daily_sum = mean(temp)
  7.         drop temp
  8. }
(5,103 missing values generated)
(5,006 missing values generated)
(3,710 missing values generated)
(3,627 missing values generated)
(5,103 missing values generated)
(5,006 missing values generated)
(3,710 missing values generated)
(3,627 missing values generated)
(6,596 missing values generated)
(6,421 missing values generated)
(6,851 missing values generated)
(6,516 missing values generated)
(6,596 missing values generated)
(6,421 missing values generated)
(6,851 missing values generated)
(6,516 missing values generated)

. 
. local sides buy sell

. local types bid trade

. foreach s of local sides{
  2.         foreach t of local types{
  3.                 gen `s'_`t'_price_daily_avg = `s'_`t'_value_daily_sum / `s'_`t'_qty_daily_sum
  4.         }
  5. }
(5,006 missing values generated)
(6,421 missing values generated)
(3,627 missing values generated)
(6,516 missing values generated)

. 
. drop bid_id bid_qty bid_value bid_price bid_status trade_qty trade_value trade_price trade_qty_cum permit_holding

. duplicates drop

Duplicates in terms of all variables

(1,799 observations deleted)

. 
. label var buy_bid_qty_daily_sum "Total quantity of purchase bids placed by day (kg)"

. label var buy_bid_price_daily_avg "Average price of purchase bids placed by day (Rs/kg) = buy_bid_value_daily_sum / buy_bid_qty_daily_sum"
note: label truncated to 80 characters

. label var buy_bid_value_daily_sum "Total value of purchase bids placed by day (Rs)"

. label var sell_bid_qty_daily_sum "Total quantity of sale bids placed by day (kg)"

. label var sell_bid_price_daily_avg "Average price of sale bids placed by day (Rs/kg) = sell_bid_value_daily_sum / sell_bid_qty_daily_sum"
note: label truncated to 80 characters

. label var sell_bid_value_daily_sum "Total value of sale bids placed by day (Rs)"

. label var buy_trade_qty_daily_sum "Total quantity of permits purchased by day (kg)"

. label var buy_trade_price_daily_avg "Average price of permits purchased by day (Rs/kg) = buy_trade_value_daily_sum / buy_trade_qty_daily_sum"
note: label truncated to 80 characters

. label var buy_trade_value_daily_sum "Total value of permits purchased placed by day (Rs)"

. label var sell_trade_qty_daily_sum "Total quantity of permits sold by day (kg)"

. label var sell_trade_price_daily_avg "Average price of permits sold by day (Rs/kg) = sell_trade_value_daily_sum / sell_trade_qty_daily_sum"
note: label truncated to 80 characters

. label var sell_trade_value_daily_sum "Total value of permits sold placed by day (Rs)"

. 
. order gpcb_id commodity commodity_period date bid_day bid_day_norm ///
>         buy_bid_qty_daily_sum buy_bid_price_daily_avg buy_bid_value_daily_sum ///
>         sell_bid_qty_daily_sum sell_bid_price_daily_avg sell_bid_value_daily_sum /// 
>         buy_trade_qty_daily_sum buy_trade_price_daily_avg buy_trade_value_daily_sum ///
>         sell_trade_qty_daily_sum sell_trade_price_daily_avg sell_trade_value_daily_sum 

.         
. sort gpcb_id commodity_period date

. 
. merge m:1 date commodity using "$TRADING_DATA_OUT/index_day-commodity-period.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                           238
        from master                       166  (_merge==1)
        from using                         72  (_merge==2)

    Matched                             6,658  (_merge==3)
    -----------------------------------------

. drop _merge

. sort date gpcb_id

. 
. merge m:1 gpcb_id using "$TRADING_DATA_OUT/covariates_plant.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                            72
        from master                        72  (_merge==1)
        from using                          0  (_merge==2)

    Matched                             6,824  (_merge==3)
    -----------------------------------------

. drop _merge

. 
. rename commodity_period period

. sort gpcb_id period date

. save "$TRADING_DATA_CLEAN/panel_plant-period-date.dta", replace
(file 02DataPipeline/trading/cleaned/panel_plant-period-date.dta not found)
file 02DataPipeline/trading/cleaned/panel_plant-period-date.dta saved

. 
end of do-file

. do "$CODE_DIR/construct_datasets/construct_panel_plant-period.do"

. /************************************************************************
> Purpose:        Create Plant-Period Panel
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. ********************************************************************************
. *** Create Plant-Period Panel
. ********************************************************************************
. 
. use "$TRADING_DATA_CLEAN/panel_plant-period-date.dta", clear

. keep gpcb_id commodity period date bid_day bid_day_norm *_daily_*

. 
. local sides buy sell

. local vars bid_qty bid_value trade_qty trade_value

. 
. foreach s of local sides{
  2.         foreach v of local vars{
  3.                 bysort gpcb_id commodity: egen temp = sum(`s'_`v'_daily_sum)
  4.                 bysort gpcb_id commodity: egen `s'_`v'_period_sum = mean(temp)
  5.                 drop temp
  6.         }
  7.         gen `s'_bid_price_period_avg = `s'_bid_value_period_sum / `s'_bid_qty_period_sum 
  8.         gen `s'_trade_price_period_avg = `s'_trade_value_period_sum / `s'_trade_qty_period_sum
  9. }
(1,740 missing values generated)
(1,955 missing values generated)
(1,387 missing values generated)
(1,792 missing values generated)

. 
. label var buy_bid_qty_period_sum "Total quantity of purchase bids placed by period (kg)"

. label var buy_bid_price_period_avg "Average price of purchase bids placed by period (Rs/kg) = buy_bid_value_period_sum / buy_bid_qty_period_sum"
note: label truncated to 80 characters

. label var buy_bid_value_period_sum "Total value of purchase bids placed by period (Rs)"

. label var sell_bid_qty_period_sum "Total quantity of sale bids placed by period (kg)"

. label var sell_bid_price_period_avg "Average price of sale bids placed by period (Rs/kg) = sell_bid_value_period_sum / sell_bid_qty_period_sum"
note: label truncated to 80 characters

. label var sell_bid_value_period_sum "Total value of sale bids placed by period (Rs)"

. label var buy_trade_qty_period_sum "Total quantity of permits purchased by period (kg)"

. label var buy_trade_price_period_avg "Average price of permits purchased by period (Rs/kg) = buy_trade_value_period_sum / buy_trade_qty_period_sum"
note: label truncated to 80 characters

. label var buy_trade_value_period_sum "Total value of permits purchased placed by period (Rs)"

. label var sell_trade_qty_period_sum "Total quantity of permits sold by period (kg)"

. label var sell_trade_price_period_avg "Average price of permits sold by period (Rs/kg) = sell_trade_value_period_sum / sell_trade_qty_period_sum"
note: label truncated to 80 characters

. label var sell_trade_value_period_sum "Total value of permits sold placed period day (Rs)"

. 
. drop date bid_day bid_day_norm *_daily_*

. sort gpcb_id period 

. duplicates drop

Duplicates in terms of all variables

(5,345 observations deleted)

. drop if missing(gpcb_id)
(11 observations deleted)

. 
. rename period commodity_period

. merge 1:1 gpcb_id commodity_period using "$TRADING_DATA_OUT/inventory_plant-commodity.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                            20
        from master                         0  (_merge==1)
        from using                         20  (_merge==2)

    Matched                             1,540  (_merge==3)
    -----------------------------------------

. drop _merge

. sort gpcb_id commodity_period 

. foreach var of varlist *_period_* {
  2.         replace `var' = 0 if missing(`var')
  3. }
(20 real changes made)
(20 real changes made)
(20 real changes made)
(20 real changes made)
(564 real changes made)
(604 real changes made)
(20 real changes made)
(20 real changes made)
(20 real changes made)
(20 real changes made)
(606 real changes made)
(735 real changes made)

. 
. ********************************************************************************
. *** Check Inconsistency 
. ********************************************************************************
. 
. preserve 

. gen my_final_inventory = allocated_quantity + buy_trade_qty_period_sum + sell_trade_qty_period_sum - consumed_period

. keep gpcb_id commodity commodity_period buy_trade_qty_period_sum purchased_period sell_trade_qty_period_sum sold_period my_final_inventory final_inventory_period

. order gpcb_id commodity commodity_period buy_trade_qty_period_sum purchased_period sell_trade_qty_period_sum sold_period my_final_inventory final_inventory_period

. drop if (buy_trade_qty_period_sum == purchased_period) & (sell_trade_qty_period_sum == -sold_period) & (my_final_inventory == final_inventory_period)
(1,335 observations deleted)

. sort commodity_period gpcb_id

. // br
. * 225 / 1560 plant-period observations are inconsistent.
. * This should be the same as in clean_trading_data.do
. restore

. 
. ********************************************************************************
. *** Prepare Data for Structural Model 
. ********************************************************************************
. 
. rename commodity_period period

. merge m:1 period using "$TRADING_DATA_OUT/index_period.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                             1,560  (_merge==3)
    -----------------------------------------

. drop _merge

. 
. * Rename variables
. rename period period_num

. rename allocated_quantity permit_alloc

. rename final_inventory_period permit_inventory

. rename consumed_period emission_val

. rename purchased_period permit_purchased 

. rename sold_period permit_sold

. rename buy_trade_price_period_avg price_permit_trade_purchase

. rename sell_trade_price_period_avg price_permit_trade_sale

. rename buy_bid_price_period_avg price_permit_bid_purchase

. rename sell_bid_price_period_avg price_permit_bid_sale

. rename period_end_commodity period_end

. rename period_end_compliance compliance_end

. rename compliance_month_cap period_cap_prorated

. 
. * Generate new variables
. gen permit_hold = permit_inventory + emission_val

. gen permit_trade = permit_hold - permit_alloc

. gen permit_trade_2 = permit_purchased - permit_sold

. gen D_non_compliance = (permit_inventory < 0)

. gen price_edc = 200

. gen amount_edc = 0

. replace amount_edc = price_edc * permit_inventory if D_non_compliance == 1
(17 real changes made)

. 
. label var permit_hold "Total permits holdings (kg)"

. label var permit_trade "Total permits traded (kg) = permits holdings -  permits allocation"

. label var permit_trade_2 "Total permits traded (kg) = permits purchased - permits sold"

. label var D_non_compliance "=1 if not compliant"

. label var price_edc "EDC price (Rs/kg)"

. label var amount_edc "EDC amount (Rs)" 

. 
. * Generate pro-rated version
. foreach var of varlist permit_alloc permit_inventory permit_hold permit_trade permit_purchased permit_sold emission_val amount_edc {
  2.         gen `var'_prorated = (`var' / compliance_length) * 30
  3. }

. * When permits are allocated, the expected period length was 31 days.
. replace permit_alloc_prorated = permit_alloc / 31 * 30 if period_num == 6 
(156 real changes made)

. 
. label var emission_val_prorated "Validate total emissions (monthly pro-rated kg)"

. label var permit_alloc_prorated "Permit allocation (monthly pro-rated kg)"

. label var permit_hold_prorated "Total permit holdings, end of period (monthly pro-rated kg)"

. label var permit_inventory_prorated "Final permit holdings, end of period (monthly pro-rated kg)"

. label var permit_trade_prorated "Net permit purchases/sales (monthly pro-rated kg)"

. label var permit_purchased_prorated "Gross purchases of permits (monthly pro-rated kg)" 

. label var permit_sold_prorated "Gross sales of permits (monthly pro-rated kg)" 

. label var amount_edc_prorated "EDC amount (monthly pro-rated Rs)" 

. 
. * Set zero price to missing
. foreach var of varlist price_permit_trade_purchase price_permit_trade_sale price_permit_bid_purchase price_permit_bid_sale{
  2.         replace `var' = . if `var' == 0
  3. }
(604 real changes made, 604 to missing)
(735 real changes made, 735 to missing)
(564 real changes made, 564 to missing)
(606 real changes made, 606 to missing)

. 
. keep gpcb_id period_num commodity period_start period_end period_length compliance_end compliance_length period_cap_prorated emission_val_prorated permit_alloc_prorated permit_hold_prorated permit_inventory_prorated permit_trade_prorated permit_purchase
> d_prorated permit_sold_prorated price_permit_trade_purchase price_permit_trade_sale price_permit_bid_purchase price_permit_bid_sale D_non_compliance price_edc amount_edc_prorated

. order gpcb_id period_num period_start period_end period_length compliance_end compliance_length period_cap_prorated emission_val_prorated permit_alloc_prorated permit_hold_prorated permit_inventory_prorated permit_trade_prorated permit_purchased_prorate
> d permit_sold_prorated price_permit_trade_purchase price_permit_trade_sale price_permit_bid_purchase price_permit_bid_sale D_non_compliance price_edc amount_edc_prorated

. sort gpcb_id period_num

. 
. // br if (permit_purchased > 0 & price_permit_trade_purchase == .) | (permit_sold > 0 & price_permit_trade_sale == .) | ///
. //      (permit_purchased == 0 & price_permit_trade_purchase != .) | (permit_sold == 0 & price_permit_trade_sale != .)
. * 59 / 1560 plant-period observations are problematic.
. 
. save "$TRADING_DATA_CLEAN/panel_plant-period.dta", replace
(file 02DataPipeline/trading/cleaned/panel_plant-period.dta not found)
file 02DataPipeline/trading/cleaned/panel_plant-period.dta saved

. 
end of do-file

. 
. ************** Create scheme **************
. grstyle init

. grstyle yesno draw_major_hgrid no

. grstyle yesno draw_major_vgrid yes

. grstyle linepattern major_grid solid

. 
. ** Plot descriptive figures
. * Figure 2
. do "$CODE_DIR/plot_time_series.do"

. /************************************************************************
> Purpose: Plot Permit Prices and Quantities Time Series  
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period-date-bid.dta", clear

. drop if bid_status == "REJ"
(0 observations deleted)

. drop if missing(bid_qty)
(3 observations deleted)

. format date %tddd-Mon-YY

. 
. ** Toggles
. local price = 1

. local quantity = 1

. 
. ********************************************************************************
. *** Price 
. ********************************************************************************
. 
. if `price' == 1 {
. 
.         preserve
.         
.         ** drop outlier
.         drop if date == td(08feb2021) & commodity == "PSUM010121"
(17 observations deleted)
.         
.         bysort period date: egen trade_price_day = mean(trade_price)
(530 missing values generated)
.         bysort period date: egen bid_price_day = mean(bid_price)
.         keep date period trade_price_day bid_price_day is_auction
.         sort date period
.         duplicates drop

Duplicates in terms of all variables

(8,133 observations deleted)
. 
.         local xtext_pos = 51    
.         local x_opt ///
>                 xtick(21746 21777 21808 21838 21869 21899 21930 21961 21990 22021 22051 22082 22112 22143 22174 22204 22235 22265 22296 22327 22355 22386) ///
>                 xlabel(21746 21838 21930 22021 22112 22204 22296 22386, angle(30) labsize(small)) ///
>                 xline(21745, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21746 "Mock-I", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21774, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21775 "Mock-II", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21808, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21809 "Period-I", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21823, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21838, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21839 "Period-II", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21853.5, lwidth(5.5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21869, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21870 "Period-III", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21892, lwidth(8.2) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21915, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21916 "Period-IV", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21930.5, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21946, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21947 "Period-V", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21960.5, lwidth(5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21975, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21976 "Period-VI", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21985.5, lwidth(3.5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21996, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21997 "Interregnum", place(se) orientation(vertical) size(vsmall) color(edkblue%70)) ///
>                 xline(22098, lwidth(37.5) lcolor(ebg%50) lpattern(solid)) ///
>                 xline(22200, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22201 "Mock-III", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22231, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22232 "Interregnum", place(se) orientation(vertical) size(vsmall) color(edkblue%70)) ///
>                 xline(22240.5, lwidth(3.4) lcolor(ebg%50) lpattern(solid)) ///
>                 xline(22250, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22251 "Period-VII", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22265.5, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22281, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22282 "Period-VIII", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22296.5, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22312, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22313 "Period-IX", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22326, lwidth(5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22340, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22341 "Period-X", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22355.5, lwidth(5.5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22371, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 xline(22380, lwidth(3) lcolor(gs14%30) lpattern(solid)) 
. 
.         twoway ///
>                 line trade_price_day date if period == 1, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line trade_price_day date if period == 2, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line trade_price_day date if period == 3, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line trade_price_day date if period == 4, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line trade_price_day date if period == 5, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line trade_price_day date if period == 6 & date <= td(22mar2020), ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line trade_price_day date if period == 7, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line trade_price_day date if period == 8, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line trade_price_day date if period == 9, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line trade_price_day date if period == 10, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 scatter bid_price_day date if period == 1 & is_auction == 1, msize(vsmall) mcolor(midblue) || ///
>                 scatter bid_price_day date if period == 2 & is_auction == 1, msize(vsmall) mcolor(black) || ///
>                 scatter bid_price_day date if period == 3 & is_auction == 1, msize(vsmall) mcolor(midblue) || ///
>                 scatter bid_price_day date if period == 4 & is_auction == 1, msize(vsmall) mcolor(black) || ///
>                 scatter bid_price_day date if period == 5 & is_auction == 1, msize(vsmall) mcolor(midblue) || ///
>                 scatter bid_price_day date if period == 6 & is_auction == 1 & date <= td(22mar2020), msize(vsmall) mcolor(black)  || ///
>                 scatter bid_price_day date if period == 7 & is_auction == 1, msize(vsmall) mcolor(midblue) || ///
>                 scatter bid_price_day date if period == 8 & is_auction == 1, msize(vsmall) mcolor(black)  || ///
>                 scatter bid_price_day date if period == 9 & is_auction == 1, msize(vsmall) mcolor(midblue) || ///
>                 scatter bid_price_day date if period == 10 & is_auction == 1, msize(vsmall) mcolor(black)  || ///
>                 pci 4.825 21808 4.825 21996, lcolor(red) lwidth(vthin) lpattern(dash) || ///
>                 pci 4.825 22250 4.825 22380, lcolor(red) lwidth(vthin) lpattern(dash) ///
>                 plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                 xtitle("") ///
>                 ytitle("Permit price (Rs/kg)", size(small)) ///
>                 ylabel(0(5)50, labsize(small) angle(horizontal)) ///
>                 xsize(14) ysize(10) ///
>                 legend(cols(3) size(small) region(lstyle(none)) position(6)) ///
>                 legend(on order(1 "Market-clearing price" 11 "Bid price" 21 "Price floor")) ///
>                 `x_opt'
. 
.         graph export "$TRADING_FIGS/Figure_2_A.pdf", replace
file 03Output/figures/Figure_2_A.pdf saved as PDF format
. 
.         restore
. }

. 
. 
. ********************************************************************************
. *** Quantity
. ********************************************************************************
. 
. if `quantity' == 1{
. 
.         preserve
.         
.         gen purchase_qty = trade_qty
(4,658 missing values generated)
.         replace purchase_qty = 0 if missing(purchase_qty) | purchase_qty < 0
(6,415 real changes made)
.         bysort date period: egen purchase_qty_day = sum(purchase_qty)
.         gen purchase_qty_day_per_cap = purchase_qty_day / compliance_cap * 100
.         keep date period purchase_qty_day_per_cap
.         sort date period
. 
.         local xtext_pos = 25.5
.         local x_opt xtick(21746 21777 21808 21838 21869 21899 21930 21961 21990 22021 22051 22082 22112 22143 22174 22204 22235 22265 22296 22327 22355 22386) ///
>                 xlabel(21746 21838 21930 22021 22112 22204 22296 22386, angle(30) labsize(small)) ///
>                 xline(21745, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21746 "Mock-I", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21774, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21775 "Mock-II", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21808, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21809 "Period-I", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21823, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21838, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21839 "Period-II", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21853.5, lwidth(5.5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21869, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21870 "Period-III", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21892, lwidth(8.2) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21915, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21916 "Period-IV", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21930.5, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21946, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21947 "Period-V", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21960.5, lwidth(5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21975, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21976 "Period-VI", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(21985.5, lwidth(3.5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(21996, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 21997 "Interregnum", place(se) orientation(vertical) size(vsmall) color(edkblue%70)) ///
>                 xline(22098, lwidth(37.5) lcolor(ebg%50) lpattern(solid)) ///
>                 xline(22200, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22201 "Mock-III", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22231, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22232 "Interregnum", place(se) orientation(vertical) size(vsmall) color(edkblue%70)) ///
>                 xline(22240.5, lwidth(3.4) lcolor(ebg%50) lpattern(solid)) ///
>                 xline(22250, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22251 "Period-VII", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22265.5, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22281, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22282 "Period-VIII", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22296.5, lwidth(5.4) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22312, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22313 "Period-IX", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22326, lwidth(5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22340, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 text(`xtext_pos' 22341 "Period-X", place(se) orientation(vertical) size(vsmall) color(gs8)) ///
>                 xline(22355.5, lwidth(5.5) lcolor(gs14%30) lpattern(solid)) ///
>                 xline(22371, lwidth(vthin) lcolor(black) lpattern(tight_dot)) ///
>                 xline(22380, lwidth(3) lcolor(gs14%30) lpattern(solid)) 
. 
.         twoway ///
>                 line purchase_qty_day_per_cap date if period == 1, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 2, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 3, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 4, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 5, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 6 & date <= td(22mar2020), ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 7, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 8, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 9, ///
>                 clwidth(thin) clcolor(midblue) mcolor(midblue) || ///
>                 line purchase_qty_day_per_cap date if period == 10, ///
>                 clwidth(thin) clcolor(black) mcolor(midblue) ///        
>                 plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                 xtitle("") ///
>                 ytitle("Permits purchased / period cap (%)", size(small)) ///
>                 ylabel(0(5)25, labsize(small) angle(horizontal)) ///
>                 xsize(14) ysize(10) aspect(0.4) ///
>                 legend(cols(1) size(small) region(lstyle(none))) ///
>                 legend(off order(1 "Trade Price" 11 "Average Order Price")) ///
>                 `x_opt'
. 
.         graph export "$TRADING_FIGS/Figure_2_B.pdf", replace
file 03Output/figures/Figure_2_B.pdf saved as PDF format
. 
.         restore
. 
. }

. 
end of do-file

. * Figure 3
. do "$CODE_DIR/plot_histogram_permit_consumption.do" 3

. /************************************************************************
> Purpose: Plot Histograms of Permit Consumption (i.e. Emissions).
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. local figure "`1'"

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period.dta", clear

. 
. if "`figure'" == "F3" {
.         * Use unadjusted emissions (see footnote 22 in the main text)
.         merge 1:1 gpcb_id period_num using "$TRADING_DATA_CLEAN/panel_plant-period_unadjusted_emissions.dta", ///
>         assert(master match) nogen
.         
.         * Confirm 37 plants need emissions unadjusted
.         qui: count if !missing(emission_val_noadjust_prorated)
.         assert `r(N)' == 37
.         
.         replace emission_val_prorated = emission_val_noadjust_prorated if !missing(emission_val_noadjust_prorated)
.         drop emission_val_noadjust_prorated
. }

. 
. ** Normalized emissions
. gen emission_per_alloc = emission_val_prorated / permit_alloc_prorated * 100
(6 missing values generated)

. gen emission_per_holding = emission_val_prorated / permit_hold_prorated * 100
(13 missing values generated)

. 
. 
. ********************************************************************************
. *** Emissions / Allocation 
. ********************************************************************************
. if "`figure'" == "3" {
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_val_prorated >= 0
  5.                 
.                 ** Truncate at 500%
.                 keep if emission_per_alloc < 500
  6.                 
.                 hist emission_per_alloc, ///
>                         width(25) start(0)  xscale(range(0 500)) ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / allocation (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)
  7. 
.                 restore
  8. 
.         }
(1,404 observations deleted)
(0 observations deleted)
(5 observations deleted)
(bin=18, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(6 observations deleted)
(bin=20, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(7 observations deleted)
(bin=17, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(5 observations deleted)
(bin=20, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(5 observations deleted)
(bin=18, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(4 observations deleted)
(bin=17, start=0, width=25)
(1,404 observations deleted)
(1 observation deleted)
(6 observations deleted)
(bin=19, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(4 observations deleted)
(bin=19, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(3 observations deleted)
(bin=20, start=0, width=25)
(1,404 observations deleted)
(0 observations deleted)
(4 observations deleted)
(bin=16, start=0, width=25)
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.                 
.         graph export "$TRADING_FIGS/Figure_3.pdf", replace
file 03Output/figures/Figure_3.pdf saved as PDF format
. 
. }

. 
. ********************************************************************************
. *** Emission / Total Holdings
. ********************************************************************************
. if "`figure'" == "4" {
.         
.         *** Force values of 100 to be just below 100 to highlight non compliers
.         gen emission_per_holding_hist = emission_per_holding - 0.00001
.         replace emission_per_holding_hist = 0 if emission_per_holding == 0
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_per_holding >= 0
  5.                 
.                 ** Truncate at 135%
.                 keep if emission_per_holding < 135
  6.                 
.                 hist emission_per_holding_hist, ///
>                         width(10) start(0) xlabel(0(20)140)  ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / total holding (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)
  7.                         
.                 restore
  8.                 
.         }
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.         
.         graph export "$TRADING_FIGS/Figure_4.pdf", replace
. 
. }

. 
. if "`figure'" == "F3" {
.         * Use unadjusted emissions
.         
.         *** Force values of 100 to be just below 100 to highlight non compliers
.         gen emission_per_holding_hist = emission_per_holding - 0.00001
.         replace emission_per_holding_hist = 0 if emission_per_holding == 0
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_per_holding >= 0
  5.                 
.                 ** Set ratio greater than 200% to 200.1 to display on graph in >200 bar 
.                 replace emission_per_holding_hist = cond(emission_per_holding_hist > 200 & !missing(emission_per_holding_hist), 200.1, emission_per_holding_hist)
  6.                 
.                 hist emission_per_holding_hist, ///
>                         width(10) start(0) xlabel(0 "0" 25 "25" 50 "50" 75 "75" 100 "100" 125 "125" 150 "150" 175 "175" 200 ">200") ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / total holding (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace) width(12.5)
  7.                         
.                 restore
  8.                 
.         }
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.         
.         graph export "$TRADING_FIGS/Figure_F3.pdf", replace
. 
. }

. 
end of do-file

. * Figure 4
. do "$CODE_DIR/plot_histogram_permit_consumption.do" 4

. /************************************************************************
> Purpose: Plot Histograms of Permit Consumption (i.e. Emissions).
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. local figure "`1'"

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period.dta", clear

. 
. if "`figure'" == "F3" {
.         * Use unadjusted emissions (see footnote 22 in the main text)
.         merge 1:1 gpcb_id period_num using "$TRADING_DATA_CLEAN/panel_plant-period_unadjusted_emissions.dta", ///
>         assert(master match) nogen
.         
.         * Confirm 37 plants need emissions unadjusted
.         qui: count if !missing(emission_val_noadjust_prorated)
.         assert `r(N)' == 37
.         
.         replace emission_val_prorated = emission_val_noadjust_prorated if !missing(emission_val_noadjust_prorated)
.         drop emission_val_noadjust_prorated
. }

. 
. ** Normalized emissions
. gen emission_per_alloc = emission_val_prorated / permit_alloc_prorated * 100
(6 missing values generated)

. gen emission_per_holding = emission_val_prorated / permit_hold_prorated * 100
(13 missing values generated)

. 
. 
. ********************************************************************************
. *** Emissions / Allocation 
. ********************************************************************************
. if "`figure'" == "3" {
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_val_prorated >= 0
  5.                 
.                 ** Truncate at 500%
.                 keep if emission_per_alloc < 500
  6.                 
.                 hist emission_per_alloc, ///
>                         width(25) start(0)  xscale(range(0 500)) ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / allocation (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)
  7. 
.                 restore
  8. 
.         }
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.                 
.         graph export "$TRADING_FIGS/Figure_3.pdf", replace
. 
. }

. 
. ********************************************************************************
. *** Emission / Total Holdings
. ********************************************************************************
. if "`figure'" == "4" {
.         
.         *** Force values of 100 to be just below 100 to highlight non compliers
.         gen emission_per_holding_hist = emission_per_holding - 0.00001
(13 missing values generated)
.         replace emission_per_holding_hist = 0 if emission_per_holding == 0
(16 real changes made)
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_per_holding >= 0
  5.                 
.                 ** Truncate at 135%
.                 keep if emission_per_holding < 135
  6.                 
.                 hist emission_per_holding_hist, ///
>                         width(10) start(0) xlabel(0(20)140)  ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / total holding (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)
  7.                         
.                 restore
  8.                 
.         }
(1,404 observations deleted)
(0 observations deleted)
(2 observations deleted)
(bin=12, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(1 observation deleted)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(3 observations deleted)
(bin=11, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(1 observation deleted)
(bin=11, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 observations deleted)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 observations deleted)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(1 observation deleted)
(2 observations deleted)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(8 observations deleted)
(bin=13, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(2 observations deleted)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(1 observation deleted)
(bin=10, start=0, width=10)
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.         
.         graph export "$TRADING_FIGS/Figure_4.pdf", replace
file 03Output/figures/Figure_4.pdf saved as PDF format
. 
. }

. 
. if "`figure'" == "F3" {
.         * Use unadjusted emissions
.         
.         *** Force values of 100 to be just below 100 to highlight non compliers
.         gen emission_per_holding_hist = emission_per_holding - 0.00001
.         replace emission_per_holding_hist = 0 if emission_per_holding == 0
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_per_holding >= 0
  5.                 
.                 ** Set ratio greater than 200% to 200.1 to display on graph in >200 bar 
.                 replace emission_per_holding_hist = cond(emission_per_holding_hist > 200 & !missing(emission_per_holding_hist), 200.1, emission_per_holding_hist)
  6.                 
.                 hist emission_per_holding_hist, ///
>                         width(10) start(0) xlabel(0 "0" 25 "25" 50 "50" 75 "75" 100 "100" 125 "125" 150 "150" 175 "175" 200 ">200") ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / total holding (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace) width(12.5)
  7.                         
.                 restore
  8.                 
.         }
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.         
.         graph export "$TRADING_FIGS/Figure_F3.pdf", replace
. 
. }

. 
end of do-file

. * Figure F3
. do "$CODE_DIR/plot_histogram_permit_consumption.do" F3

. /************************************************************************
> Purpose: Plot Histograms of Permit Consumption (i.e. Emissions).
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. local figure "`1'"

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period.dta", clear

. 
. if "`figure'" == "F3" {
.         * Use unadjusted emissions (see footnote 22 in the main text)
.         merge 1:1 gpcb_id period_num using "$TRADING_DATA_CLEAN/panel_plant-period_unadjusted_emissions.dta", ///
>         assert(master match) nogen

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,523
        from master                     1,523  
        from using                          0  

    Matched                                37  
    -----------------------------------------
.         
.         * Confirm 37 plants need emissions unadjusted
.         qui: count if !missing(emission_val_noadjust_prorated)
.         assert `r(N)' == 37
.         
.         replace emission_val_prorated = emission_val_noadjust_prorated if !missing(emission_val_noadjust_prorated)
(37 real changes made)
.         drop emission_val_noadjust_prorated
. }

. 
. ** Normalized emissions
. gen emission_per_alloc = emission_val_prorated / permit_alloc_prorated * 100
(6 missing values generated)

. gen emission_per_holding = emission_val_prorated / permit_hold_prorated * 100
(13 missing values generated)

. 
. 
. ********************************************************************************
. *** Emissions / Allocation 
. ********************************************************************************
. if "`figure'" == "3" {
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_val_prorated >= 0
  5.                 
.                 ** Truncate at 500%
.                 keep if emission_per_alloc < 500
  6.                 
.                 hist emission_per_alloc, ///
>                         width(25) start(0)  xscale(range(0 500)) ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / allocation (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)
  7. 
.                 restore
  8. 
.         }
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.                 
.         graph export "$TRADING_FIGS/Figure_3.pdf", replace
. 
. }

. 
. ********************************************************************************
. *** Emission / Total Holdings
. ********************************************************************************
. if "`figure'" == "4" {
.         
.         *** Force values of 100 to be just below 100 to highlight non compliers
.         gen emission_per_holding_hist = emission_per_holding - 0.00001
.         replace emission_per_holding_hist = 0 if emission_per_holding == 0
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_per_holding >= 0
  5.                 
.                 ** Truncate at 135%
.                 keep if emission_per_holding < 135
  6.                 
.                 hist emission_per_holding_hist, ///
>                         width(10) start(0) xlabel(0(20)140)  ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / total holding (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)
  7.                         
.                 restore
  8.                 
.         }
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.         
.         graph export "$TRADING_FIGS/Figure_4.pdf", replace
. 
. }

. 
. if "`figure'" == "F3" {
.         * Use unadjusted emissions
.         
.         *** Force values of 100 to be just below 100 to highlight non compliers
.         gen emission_per_holding_hist = emission_per_holding - 0.00001
(13 missing values generated)
.         replace emission_per_holding_hist = 0 if emission_per_holding == 0
(16 real changes made)
. 
.         forval i=1/10 {
  2.                 
.                 preserve
  3.                 
.                 keep if period_num == `i'
  4.                 
.                 ** Drop if emission is negative
.                 keep if emission_per_holding >= 0
  5.                 
.                 ** Set ratio greater than 200% to 200.1 to display on graph in >200 bar 
.                 replace emission_per_holding_hist = cond(emission_per_holding_hist > 200 & !missing(emission_per_holding_hist), 200.1, emission_per_holding_hist)
  6.                 
.                 hist emission_per_holding_hist, ///
>                         width(10) start(0) xlabel(0 "0" 25 "25" 50 "50" 75 "75" 100 "100" 125 "125" 150 "150" 175 "175" 200 ">200") ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Emissions / total holding (%)") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace) width(12.5)
  7.                         
.                 restore
  8.                 
.         }
(1,404 observations deleted)
(0 observations deleted)
(1 real change made)
(bin=21, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 real changes made)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(2 real changes made)
(bin=21, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 real changes made)
(bin=16, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 real changes made)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 real changes made)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(11 real changes made)
(bin=21, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(1 real change made)
(bin=21, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 real changes made)
(bin=10, start=0, width=10)
(1,404 observations deleted)
(0 observations deleted)
(0 real changes made)
(bin=10, start=0, width=10)
.         
.         graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>                 colfirst cols(2) ysize(10) xsize(6) xcommon ycommon ///
>                 graphregion(fcolor(white)) plotregion(fcolor(white))
.         
.         graph export "$TRADING_FIGS/Figure_F3.pdf", replace
file 03Output/figures/Figure_F3.pdf saved as PDF format
. 
. }

. 
end of do-file

. * Figure B2
. do "$CODE_DIR/plot_histogram_number_bids.do"

. /************************************************************************
> Authors: Kaixin Wang
> Project: ETS
> Purpose: Plot Histograms of Numbers of Orders.
> 
> Date created: 4 March 2022
> Version:      STATA 17 MP
> 
> Last edited: 11 June 2022
> Edited by:   Kaixin     
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period-date-bid.dta", clear

. drop if bid_status == "REJ"
(0 observations deleted)

. drop if missing(bid_qty)
(3 observations deleted)

. sort gpcb_id period date bid_id 

. 
. ********************************************************************************
. *** Distribution of # of bids per plant in a compliance period
. ********************************************************************************
. 
. bysort gpcb_id period: gen num_order = _N

. keep gpcb_id commodity num_order

. duplicates drop

Duplicates in terms of all variables

(7,062 observations deleted)

. merge m:1 gpcb_id commodity using "$TRADING_DATA_OUT/inventory_plant-commodity.dta", keepusing(commodity_period)

    Result                      Number of obs
    -----------------------------------------
    Not matched                           189
        from master                         0  (_merge==1)
        from using                        189  (_merge==2)

    Matched                             1,371  (_merge==3)
    -----------------------------------------

. drop _merge commodity

. rename commodity_period period

. replace num_order = 0 if missing(num_order)
(189 real changes made)

. sort gpcb_id period

. order gpcb_id period

. 
. forval i=1/10 {
  2.         
.         preserve
  3.         
.         keep if period == `i'
  4.         
.         ** compute median number of order
.         sum num_order, detail
  5.         local median_order = r(p50)
  6.         
.         ** truncate at 40
.         keep if num_order < 40
  7.         
.         if `i' == 6 {
  8.                 hist num_order, discrete legend(off) start(-0.5) ///
>                         width(1) addplot(pci 0 `median_order' 0.5 `median_order') ///
>                         text(0.4 `median_order'  "Median: `median_order'", size(small) place(se) color(red)) ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Number of bids") ///
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)      
  9.         }
 10.         else {
 11.                 hist num_order, discrete legend(off) start(-0.5) ///
>                         width(1) addplot(pci 0 `median_order' 0.25 `median_order') ///
>                         text(0.2 `median_order'  "Median: `median_order'", size(small) place(se) color(red)) ///
>                         color(midblue*0.6) lcolor(midblue) ///
>                         title("Period `i'", size(medium)) ///
>                         xtitle("Number of bids") /// 
>                         plotregion(color(white)) bgcolor(white) graphregion(color(white)) ///
>                         name("graph_`i'", replace)
 12.         }
 13.         
.         restore
 14. }
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            3              0       Sum of wgt.         156

50%            7                      Mean           9.775641
                        Largest       Std. dev.      10.42551
75%           12             46
90%           23             47       Variance       108.6913
95%           33             47       Skewness       1.896283
99%           47             54       Kurtosis       6.865902
(4 observations deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            0              0       Obs                 156
25%            1              0       Sum of wgt.         156

50%            3                      Mean           3.846154
                        Largest       Std. dev.      4.084832
75%            5             18
90%            8             20       Variance       16.68586
95%           13             21       Skewness       2.167397
99%           21             22       Kurtosis       8.570718
(0 observations deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            3              0       Sum of wgt.         156

50%            5                      Mean           6.948718
                        Largest       Std. dev.      6.736319
75%            9             29
90%           13             30       Variance         45.378
95%           21             30       Skewness        2.46767
99%           30             46       Kurtosis       11.65641
(1 observation deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            2              0       Sum of wgt.         156

50%            3                      Mean           5.166667
                        Largest       Std. dev.      6.103234
75%            7             20
90%           11             24       Variance       37.24946
95%           15             25       Skewness       4.002129
99%           25             54       Kurtosis       28.74193
(1 observation deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            2              0       Sum of wgt.         156

50%            3                      Mean           4.916667
                        Largest       Std. dev.      6.988431
75%          5.5             19
90%           11             22       Variance       48.83817
95%           15             35       Skewness       5.361706
99%           35             67       Kurtosis       43.39469
(1 observation deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            0              0       Obs                 156
25%            0              0       Sum of wgt.         156

50%            1                      Mean           1.897436
                        Largest       Std. dev.      3.195116
75%            2             13
90%            6             14       Variance       10.20877
95%            8             15       Skewness       3.104429
99%           15             22       Kurtosis       15.46546
(0 observations deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            1              0       Sum of wgt.         156

50%            3                      Mean           4.141026
                        Largest       Std. dev.      4.540071
75%            5             16
90%            9             21       Variance       20.61224
95%           11             24       Skewness        3.58183
99%           24             37       Kurtosis       22.26241
(0 observations deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            2              0       Sum of wgt.         156

50%            3                      Mean           5.019231
                        Largest       Std. dev.      6.350485
75%            6             25
90%           11             30       Variance       40.32866
95%           18             36       Skewness       3.075492
99%           36             42       Kurtosis       14.60133
(1 observation deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            1              0       Sum of wgt.         156

50%            3                      Mean           6.166667
                        Largest       Std. dev.      9.707219
75%            6             33
90%           14             39       Variance       94.23011
95%           25             60       Skewness       4.068023
99%           60             74       Kurtosis       23.80958
(2 observations deleted)
(start=-.5, width=1)
(1,404 observations deleted)

                          num_order
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%            1              0       Obs                 156
25%            1              0       Sum of wgt.         156

50%            3                      Mean           6.179487
                        Largest       Std. dev.      8.846714
75%            8             33
90%           14             43       Variance       78.26435
95%           20             58       Skewness       3.579023
99%           58             59       Kurtosis       19.12858
(3 observations deleted)
(start=-.5, width=1)

. 
. graph combine graph_1 graph_2 graph_3 graph_4 graph_5 graph_6 graph_7 graph_8 graph_9 graph_10, ///
>         colfirst cols(2) ysize(10) xsize(6) xcommon ///
>         graphregion(fcolor(white)) plotregion(fcolor(white))

.         
. graph export "$TRADING_FIGS/Figure_B2.pdf", replace
file 03Output/figures/Figure_B2.pdf saved as PDF format

. 
end of do-file

. 
. ** Estimate elasticity of marginal cost with respect to emissions
. * Table 4
. do "$CODE_DIR/make_elasticity_table_hetero.do"

. /************************************************************************
> Purpose: Make elasticity table in the ETS paper
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period-date-bid.dta", clear

. drop if bid_status == "REJ"
(0 observations deleted)

. drop if missing(bid_qty)
(3 observations deleted)

. sort gpcb_id period date bid_id 

. 
. 
. // There are 8433 bids overall in our data and 3120 offered in the first half of a compliance period. Of these bids, 345 were offered by plants that had only a single bid in the first half of a given plant-period, and which therefore do not contribute t
> o the estimation of the key elasticity \beta_1.
. 
. preserve

. keep if bid_day_norm <= 0.5
(5,313 observations deleted)

. bysort gpcb_id period: gen num_bids = _N

. keep if num_bids == 1
(2,775 observations deleted)

. restore

. 
. 
. drop cyc_max

. drop bf_max

. // drop scr_esp_max
. 
. gen cyc_max = (D_cyc == 1) & (D_bf == 0) & (D_scr == 0) & (D_esp == 0)

. gen bf_max = (D_bf == 1) & (D_scr == 0) & (D_esp == 0)

. gen scr_max = (D_scr == 1) & (D_esp == 0)

. gen esp_max = (D_esp == 1)

. 
. gen tech_type = "."

. replace tech_type = "cyc" if cyc_max == 1
variable tech_type was str1 now str3
(64 real changes made)

. replace tech_type = "bf" if bf_max == 1
(1,708 real changes made)

. replace tech_type = "scr" if scr_max == 1
(5,219 real changes made)

. replace tech_type = "esp" if esp_max == 1
(1,329 real changes made)

. 
. 
.  
. tabulate tech_type

  tech_type |      Freq.     Percent        Cum.
------------+-----------------------------------
          . |        113        1.34        1.34
         bf |      1,708       20.25       21.59
        cyc |         64        0.76       22.35
        esp |      1,329       15.76       38.11
        scr |      5,219       61.89      100.00
------------+-----------------------------------
      Total |      8,433      100.00

. 
. tabulate tech_type if bid_day_norm <= 0.5 

  tech_type |      Freq.     Percent        Cum.
------------+-----------------------------------
          . |         38        1.22        1.22
         bf |        584       18.72       19.94
        cyc |         19        0.61       20.54
        esp |        510       16.35       36.89
        scr |      1,969       63.11      100.00
------------+-----------------------------------
      Total |      3,120      100.00

.  
. drop tech_type

. // gen tech_type = -1
. // replace tech_type = 1 if cyc_max == 1
. // replace tech_type = 2 if bf_max == 1
. // replace tech_type = 3 if scr_max == 1
. // replace tech_type = 4 if esp_max == 1
.         
. 
. *** Generate tech type
. gen tech_type = -1

. replace tech_type = 0 if cyc_max == 1 | bf_max == 1
(1,772 real changes made)

. replace tech_type = 1 if scr_esp_max == 1
(6,548 real changes made)

. 
. 
. 
. *** Keep bids placed in the first half
. keep if bid_day_norm <= 0.5
(5,313 observations deleted)

. 
. ********************************************************************************
. *** Run regressions
. ********************************************************************************
. 
. local price_var ln_bid_price

. local holding_var ln_permit_holding_hyp

. 
. 
. * 1) Control
. * First run without dropping singletons to get the number of clusters.
. eststo reg_1: reghdfe `price_var' `holding_var' ln_plant_total_heatoutput, noabsorb vce(cluster gpcb_id) keepsingletons
WARNING: Singleton observations not dropped; statistical significance is biased (link)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      3,120
Absorbing 1 HDFE group                            F(   2,    145) =       2.32
Statistics robust to heteroskedasticity           Prob > F        =     0.1020
                                                  R-squared       =     0.0062
                                                  Adj R-squared   =     0.0056
                                                  Within R-sq.    =     0.0062
Number of clusters (gpcb_id) =        146         Root MSE        =     0.6717

                                           (Std. err. adjusted for 146 clusters in gpcb_id)
-------------------------------------------------------------------------------------------
                          |               Robust
             ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------------------+----------------------------------------------------------------
    ln_permit_holding_hyp |  -.1003001   .0614467    -1.63   0.105    -.2217469    .0211468
ln_plant_total_heatoutput |   .0870067   .0408059     2.13   0.035     .0063556    .1676579
                    _cons |   1.456133   .3725419     3.91   0.000     .7198188    2.192447
-------------------------------------------------------------------------------------------

. local N_plants_temp = e(N_clust)

. * Run dropping singletons to get proper SEs, and add full plant count from first-run
. eststo reg_1: reghdfe `price_var' `holding_var' ln_plant_total_heatoutput, noabsorb vce(cluster gpcb_id)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      3,120
Absorbing 1 HDFE group                            F(   2,    145) =       2.32
Statistics robust to heteroskedasticity           Prob > F        =     0.1020
                                                  R-squared       =     0.0062
                                                  Adj R-squared   =     0.0056
                                                  Within R-sq.    =     0.0062
Number of clusters (gpcb_id) =        146         Root MSE        =     0.6717

                                           (Std. err. adjusted for 146 clusters in gpcb_id)
-------------------------------------------------------------------------------------------
                          |               Robust
             ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------------------+----------------------------------------------------------------
    ln_permit_holding_hyp |  -.1003001   .0614467    -1.63   0.105    -.2217469    .0211468
ln_plant_total_heatoutput |   .0870067   .0408059     2.13   0.035     .0063556    .1676579
                    _cons |   1.456133   .3725419     3.91   0.000     .7198188    2.192447
-------------------------------------------------------------------------------------------

. estadd local Period_FE ""

added macro:
          e(Period_FE) : ""

. estadd local Plant_FE ""

added macro:
           e(Plant_FE) : ""

. estadd local Plant_Period_FE ""

added macro:
    e(Plant_Period_FE) : ""

. estadd local N_Plants = `N_plants_temp'

added macro:
           e(N_Plants) : "146"

. estadd local space ""

added macro:
              e(space) : ""

. 
. 
. * 2) Period FE + Control
. eststo reg_2: reghdfe `price_var' `holding_var' ln_plant_total_heatoutput, a(period) vce(cluster gpcb_id) keepsingletons
WARNING: Singleton observations not dropped; statistical significance is biased (link)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      3,120
Absorbing 1 HDFE group                            F(   2,    145) =       4.14
Statistics robust to heteroskedasticity           Prob > F        =     0.0179
                                                  R-squared       =     0.0688
                                                  Adj R-squared   =     0.0655
                                                  Within R-sq.    =     0.0134
Number of clusters (gpcb_id) =        146         Root MSE        =     0.6512

                                           (Std. err. adjusted for 146 clusters in gpcb_id)
-------------------------------------------------------------------------------------------
                          |               Robust
             ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------------------+----------------------------------------------------------------
    ln_permit_holding_hyp |  -.1429144   .0632925    -2.26   0.025    -.2680095   -.0178192
ln_plant_total_heatoutput |   .1380225   .0482076     2.86   0.005      .042742    .2333029
                    _cons |   .9627289   .4616619     2.09   0.039     .0502728    1.875185
-------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
      period |        10           0          10     |
-----------------------------------------------------+

. local N_plants_temp = e(N_clust)

. eststo reg_2: reghdfe `price_var' `holding_var' ln_plant_total_heatoutput, a(period) vce(cluster gpcb_id)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      3,120
Absorbing 1 HDFE group                            F(   2,    145) =       4.14
Statistics robust to heteroskedasticity           Prob > F        =     0.0179
                                                  R-squared       =     0.0688
                                                  Adj R-squared   =     0.0655
                                                  Within R-sq.    =     0.0134
Number of clusters (gpcb_id) =        146         Root MSE        =     0.6512

                                           (Std. err. adjusted for 146 clusters in gpcb_id)
-------------------------------------------------------------------------------------------
                          |               Robust
             ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------------------+----------------------------------------------------------------
    ln_permit_holding_hyp |  -.1429144   .0632925    -2.26   0.025    -.2680095   -.0178192
ln_plant_total_heatoutput |   .1380225   .0482076     2.86   0.005      .042742    .2333029
                    _cons |   .9627289   .4616619     2.09   0.039     .0502728    1.875185
-------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
      period |        10           0          10     |
-----------------------------------------------------+

. estadd local Period_FE "Yes"

added macro:
          e(Period_FE) : "Yes"

. estadd local Plant_FE ""

added macro:
           e(Plant_FE) : ""

. estadd local Plant_Period_FE ""

added macro:
    e(Plant_Period_FE) : ""

. estadd local N_Plants = `N_plants_temp'

added macro:
           e(N_Plants) : "146"

. estadd local space ""

added macro:
              e(space) : ""

. 
. * 3) Period FE + Plant FE
. reghdfe `price_var' `holding_var', a(period gpcb_id) vce(cluster gpcb_id) keepsingletons
WARNING: Singleton observations not dropped; statistical significance is biased (link)
(MWFE estimator converged in 7 iterations)

HDFE Linear regression                            Number of obs   =      3,120
Absorbing 2 HDFE groups                           F(   1,    145) =      10.35
Statistics robust to heteroskedasticity           Prob > F        =     0.0016
                                                  R-squared       =     0.2630
                                                  Adj R-squared   =     0.2244
                                                  Within R-sq.    =     0.0211
Number of clusters (gpcb_id) =        146         Root MSE        =     0.5932

                                       (Std. err. adjusted for 146 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.2689425   .0835857    -3.22   0.002    -.4341462   -.1037387
                _cons |   4.060263   .6105205     6.65   0.000     2.853594    5.266932
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
      period |        10           1           9     |
     gpcb_id |       146         146           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. local N_plants_temp = e(N_clust)

. eststo reg_3: reghdfe `price_var' `holding_var', a(period gpcb_id) vce(cluster gpcb_id)
(dropped 8 singleton observations)
(MWFE estimator converged in 7 iterations)

HDFE Linear regression                            Number of obs   =      3,112
Absorbing 2 HDFE groups                           F(   1,    137) =      10.35
Statistics robust to heteroskedasticity           Prob > F        =     0.0016
                                                  R-squared       =     0.2621
                                                  Adj R-squared   =     0.2255
                                                  Within R-sq.    =     0.0211
Number of clusters (gpcb_id) =        138         Root MSE        =     0.5932

                                       (Std. err. adjusted for 138 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.2689425   .0836028    -3.22   0.002    -.4342612   -.1036237
                _cons |    4.06104   .6107462     6.65   0.000     2.853331    5.268748
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
      period |        10           1           9     |
     gpcb_id |       138         138           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. estadd local Period_FE "Yes"

added macro:
          e(Period_FE) : "Yes"

. estadd local Plant_FE "Yes"

added macro:
           e(Plant_FE) : "Yes"

. estadd local Plant_Period_FE ""

added macro:
    e(Plant_Period_FE) : ""

. estadd local N_Plants = `N_plants_temp'

added macro:
           e(N_Plants) : "146"

. estadd local space ""

added macro:
              e(space) : ""

. 
. * 4) Period x Plant FE
. 
. xtset plant_period

Panel variable: plant_period_id (unbalanced)

. xtreg `price_var' `holding_var', fe

Fixed-effects (within) regression               Number of obs     =      3,120
Group variable: plant_peri~d                    Number of groups  =        835

R-squared:                                      Obs per group:
     Within  = 0.0508                                         min =          1
     Between = 0.0000                                         avg =        3.7
     Overall = 0.0017                                         max =         62

                                                F(1, 2284)        =     122.27
corr(u_i, Xb) = -0.6822                         Prob > F          =     0.0000

---------------------------------------------------------------------------------------
         ln_bid_price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.6088662    .055064   -11.06   0.000     -.716847   -.5008855
                _cons |   6.543108   .4023144    16.26   0.000     5.754168    7.332048
----------------------+----------------------------------------------------------------
              sigma_u |  .67115005
              sigma_e |  .54827899
                  rho |  .59974842   (fraction of variance due to u_i)
---------------------------------------------------------------------------------------
F test that all u_i=0: F(834, 2284) = 2.90                   Prob > F = 0.0000

. estimates store fixed

. xtreg `price_var' `holding_var', re

Random-effects GLS regression                   Number of obs     =      3,120
Group variable: plant_peri~d                    Number of groups  =        835

R-squared:                                      Obs per group:
     Within  = 0.0508                                         min =          1
     Between = 0.0000                                         avg =        3.7
     Overall = 0.0017                                         max =         62

                                                Wald chi2(1)      =      17.93
corr(u_i, X) = 0 (assumed)                      Prob > chi2       =     0.0000

---------------------------------------------------------------------------------------
         ln_bid_price | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.1042937   .0246317    -4.23   0.000    -.1525709   -.0560164
                _cons |   2.786967   .1770943    15.74   0.000     2.439869    3.134065
----------------------+----------------------------------------------------------------
              sigma_u |  .35756234
              sigma_e |  .54827899
                  rho |   .2983957   (fraction of variance due to u_i)
---------------------------------------------------------------------------------------

. // hausman fixed .
. hausman fixed ., sigmamore

                 ---- Coefficients ----
             |      (b)          (B)            (b-B)     sqrt(diag(V_b-V_B))
             |     fixed          .          Difference       Std. err.
-------------+----------------------------------------------------------------
ln_permit_~p |   -.6088662    -.1042937       -.5045725        .0505395
------------------------------------------------------------------------------
                          b = Consistent under H0 and Ha; obtained from xtreg.
           B = Inconsistent under Ha, efficient under H0; obtained from xtreg.

Test of H0: Difference in coefficients not systematic

    chi2(1) = (b-B)'[(V_b-V_B)^(-1)](b-B)
            =  99.67
Prob > chi2 = 0.0000

. 
. xtreg `price_var' `holding_var', fe vce(cluster gpcb_id)

Fixed-effects (within) regression               Number of obs     =      3,120
Group variable: plant_peri~d                    Number of groups  =        835

R-squared:                                      Obs per group:
     Within  = 0.0508                                         min =          1
     Between = 0.0000                                         avg =        3.7
     Overall = 0.0017                                         max =         62

                                                F(1, 145)         =      48.76
corr(u_i, Xb) = -0.6822                         Prob > F          =     0.0000

                                       (Std. err. adjusted for 146 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.6088662    .087195    -6.98   0.000    -.7812036   -.4365289
                _cons |   6.543108    .636883    10.27   0.000     5.284335    7.801882
----------------------+----------------------------------------------------------------
              sigma_u |  .67115005
              sigma_e |  .54827899
                  rho |  .59974842   (fraction of variance due to u_i)
---------------------------------------------------------------------------------------

. xtreg `price_var' `holding_var', re vce(cluster gpcb_id)

Random-effects GLS regression                   Number of obs     =      3,120
Group variable: plant_peri~d                    Number of groups  =        835

R-squared:                                      Obs per group:
     Within  = 0.0508                                         min =          1
     Between = 0.0000                                         avg =        3.7
     Overall = 0.0017                                         max =         62

                                                Wald chi2(1)      =       4.30
corr(u_i, X) = 0 (assumed)                      Prob > chi2       =     0.0381

                                       (Std. err. adjusted for 146 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.1042937   .0503024    -2.07   0.038    -.2028845   -.0057028
                _cons |   2.786967   .3594962     7.75   0.000     2.082367    3.491567
----------------------+----------------------------------------------------------------
              sigma_u |  .35756234
              sigma_e |  .54827899
                  rho |   .2983957   (fraction of variance due to u_i)
---------------------------------------------------------------------------------------

. xtoverid

Test of overidentifying restrictions: fixed vs random effects
Cross-section time-series model: xtreg re  robust cluster(gpcb_id)
Sargan-Hansen statistic  46.213  Chi-sq(1)    P-value = 0.0000

. local p_overid = r(jp)

. 
. // Test of overidentifying restrictions: fixed vs random effects
. // Cross-section time-series model: xtreg re  robust cluster(gpcb_id)
. // Sargan-Hansen statistic  46.213  Chi-sq(1)    P-value = 0.0000
. * Rejection implies that the fixed effect model is more reasonable or preferred
. 
. reghdfe `price_var' `holding_var', a(i.plant_period) vce(cluster gpcb_id) keepsingletons
WARNING: Singleton observations not dropped; statistical significance is biased (link)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      3,120
Absorbing 1 HDFE group                            F(   1,    145) =      48.76
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5149
                                                  Adj R-squared   =     0.3375
                                                  Within R-sq.    =     0.0508
Number of clusters (gpcb_id) =        146         Root MSE        =     0.5483

                                       (Std. err. adjusted for 146 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.6088662    .087195    -6.98   0.000    -.7812036   -.4365289
                _cons |   6.543108    .636883    10.27   0.000     5.284335    7.801882
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       835         835           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. local N_plants_temp = e(N_clust)

. eststo reg_4: reghdfe `price_var' `holding_var', a(i.plant_period) vce(cluster gpcb_id) 
(dropped 345 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      2,775
Absorbing 1 HDFE group                            F(   1,    126) =      48.71
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.4590
                                                  Adj R-squared   =     0.3430
                                                  Within R-sq.    =     0.0508
Number of clusters (gpcb_id) =        127         Root MSE        =     0.5483

                                       (Std. err. adjusted for 127 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.6088662   .0872417    -6.98   0.000     -.781515   -.4362174
                _cons |   6.595025   .6414414    10.28   0.000     5.325631    7.864418
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       490         490           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. estadd local p_overid = string(`p_overid', "%15.3f")

added macro:
           e(p_overid) : "0.000"

. estadd local Period_FE ""

added macro:
          e(Period_FE) : ""

. estadd local Plant_FE ""

added macro:
           e(Plant_FE) : ""

. estadd local Plant_Period_FE "Yes"

added macro:
    e(Plant_Period_FE) : "Yes"

. estadd local N_Plants = `N_plants_temp'

added macro:
           e(N_Plants) : "146"

. estadd local space ""

added macro:
              e(space) : ""

. 
. 
. * 5) Period x Plant FE + Heterogeneity by tech type
. keep if tech_type > -1
(38 observations deleted)

. 
. gen `holding_var'_0 = `holding_var' * (tech_type == 0)

. gen `holding_var'_1 = `holding_var' * (tech_type == 1)

. xtreg `price_var' `holding_var'_0 `holding_var'_1, fe vce(cluster gpcb_id)

Fixed-effects (within) regression               Number of obs     =      3,082
Group variable: plant_peri~d                    Number of groups  =        813

R-squared:                                      Obs per group:
     Within  = 0.0505                                         min =          1
     Between = 0.0004                                         avg =        3.8
     Overall = 0.0045                                         max =         62

                                                F(2, 141)         =      26.43
corr(u_i, Xb) = -0.6994                         Prob > F          =     0.0000

                                         (Std. err. adjusted for 142 clusters in gpcb_id)
-----------------------------------------------------------------------------------------
                        |               Robust
           ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
------------------------+----------------------------------------------------------------
ln_permit_holding_hyp_0 |   -.707342   .1693938    -4.18   0.000    -1.042222   -.3724621
ln_permit_holding_hyp_1 |  -.5658437   .0950776    -5.95   0.000    -.7538057   -.3778818
                  _cons |   6.422437    .610906    10.51   0.000     5.214718    7.630157
------------------------+----------------------------------------------------------------
                sigma_u |  .73741914
                sigma_e |  .54752811
                    rho |  .64462273   (fraction of variance due to u_i)
-----------------------------------------------------------------------------------------

. xtreg `price_var' `holding_var'_0 `holding_var'_1, re vce(cluster gpcb_id)

Random-effects GLS regression                   Number of obs     =      3,082
Group variable: plant_peri~d                    Number of groups  =        813

R-squared:                                      Obs per group:
     Within  = 0.0502                                         min =          1
     Between = 0.0001                                         avg =        3.8
     Overall = 0.0029                                         max =         62

                                                Wald chi2(2)      =       5.27
corr(u_i, X) = 0 (assumed)                      Prob > chi2       =     0.0717

                                         (Std. err. adjusted for 142 clusters in gpcb_id)
-----------------------------------------------------------------------------------------
                        |               Robust
           ln_bid_price | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
------------------------+----------------------------------------------------------------
ln_permit_holding_hyp_0 |  -.1206765   .0533998    -2.26   0.024    -.2253383   -.0160148
ln_permit_holding_hyp_1 |  -.1118251   .0514573    -2.17   0.030    -.2126795   -.0109706
                  _cons |   2.856916   .3713203     7.69   0.000     2.129141     3.58469
------------------------+----------------------------------------------------------------
                sigma_u |  .36460262
                sigma_e |  .54752811
                    rho |  .30720656   (fraction of variance due to u_i)
-----------------------------------------------------------------------------------------

. xtoverid

Test of overidentifying restrictions: fixed vs random effects
Cross-section time-series model: xtreg re  robust cluster(gpcb_id)
Sargan-Hansen statistic  46.909  Chi-sq(2)    P-value = 0.0000

. local p_overid = r(jp)

. 
. reghdfe `price_var' c.`holding_var'#i.tech_type, a(i.plant_period) vce(cluster gpcb_id) keepsingletons
WARNING: Singleton observations not dropped; statistical significance is biased (link)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      3,082
Absorbing 1 HDFE group                            F(   2,    141) =      26.43
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5144
                                                  Adj R-squared   =     0.3401
                                                  Within R-sq.    =     0.0505
Number of clusters (gpcb_id) =        142         Root MSE        =     0.5475

                                                   (Std. err. adjusted for 142 clusters in gpcb_id)
---------------------------------------------------------------------------------------------------
                                  |               Robust
                     ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------------------+----------------------------------------------------------------
tech_type#c.ln_permit_holding_hyp |
                               0  |   -.707342   .1693938    -4.18   0.000    -1.042222   -.3724621
                               1  |  -.5658437   .0950776    -5.95   0.000    -.7538057   -.3778818
                                  |
                            _cons |   6.422437    .610906    10.51   0.000     5.214718    7.630157
---------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       813         813           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. local N_plants_temp = e(N_clust)

. eststo reg_5: reghdfe `price_var' c.`holding_var'#i.tech_type, a(i.plant_period) vce(cluster gpcb_id)
(dropped 329 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      2,753
Absorbing 1 HDFE group                            F(   2,    122) =      26.40
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.4598
                                                  Adj R-squared   =     0.3442
                                                  Within R-sq.    =     0.0505
Number of clusters (gpcb_id) =        123         Root MSE        =     0.5475

                                                   (Std. err. adjusted for 123 clusters in gpcb_id)
---------------------------------------------------------------------------------------------------
                                  |               Robust
                     ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------------------+----------------------------------------------------------------
tech_type#c.ln_permit_holding_hyp |
                               0  |   -.707342   .1694932    -4.17   0.000    -1.042871   -.3718132
                               1  |  -.5658437   .0951335    -5.95   0.000    -.7541699   -.3775176
                                  |
                            _cons |    6.46023   .6173222    10.46   0.000      5.23818    7.682281
---------------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       484         484           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. test 0.tech_type#c.ln_permit_holding_hyp = 1.tech_type#c.ln_permit_holding_hyp

 ( 1)  0b.tech_type#c.ln_permit_holding_hyp - 1.tech_type#c.ln_permit_holding_hyp = 0

       F(  1,   122) =    0.53
            Prob > F =    0.4680

. estadd local p_obs = string(r(p), "%15.3f")

added macro:
              e(p_obs) : "0.468"

. estadd local p_overid = string(`p_overid', "%15.3f")

added macro:
           e(p_overid) : "0.000"

. estadd local Period_FE ""

added macro:
          e(Period_FE) : ""

. estadd local Plant_FE ""

added macro:
           e(Plant_FE) : ""

. estadd local Plant_Period_FE "Yes"

added macro:
    e(Plant_Period_FE) : "Yes"

. estadd local N_Plants = `N_plants_temp'

added macro:
           e(N_Plants) : "142"

. estadd local space ""

added macro:
              e(space) : ""

. 
.  
. ********************************************************************************
. *** Output the LaTeX Table
. ************************RADING********************************************************
. 
. esttab reg_1 reg_2 reg_3 reg_4 reg_5 ///
>         using "$TRADING_TABS/Table_4.tex", replace ///
>         b(3) se(3) ar2 booktabs varwidth(32) ///
>         keep(ln_permit_holding_hyp 0.tech_type#c.ln_permit_holding_hyp 1.tech_type#c.ln_permit_holding_hyp ln_plant_total_heatoutput) ///
>         order(ln_permit_holding_hyp 0.tech_type#c.ln_permit_holding_hyp 1.tech_type#c.ln_permit_holding_hyp ln_plant_total_heatoutput) ///
>         coeflabel(ln_permit_holding_hyp "log(Emissions as bid)" ln_plant_total_heatoutput "log(Plant total heat output)" 0.tech_type#c.ln_permit_holding_hyp "log(Emissions as bid) $\times$ cyclone / bag filter" 1.tech_type#c.ln_permit_holding_hyp "log(E
> missions as bid) $\times$ scrubber / ESP") ///
>         mgroups("\shortstack{log(Bid price)}", pattern(1 0 0 0 0) ///   
>                 prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
>         nomtitles ///
>         stats(Period_FE Plant_FE Plant_Period_FE space p_overid p_obs r2 N_Plants N_full , ///
>                 label("Period FE" "Plant FE" "Plant $\times$ Period FE" " " "p-val: $ H\textsubscript{0} $: No unobserved heterogeneity" "p-val: $ H\textsubscript{0} $: No observed heterogeneity" "R\textsuperscript{2}" "Plants" "Observations") ///
>                 fmt(%1s %1s %1s 0 %9.2f %9.2f %9.2f 0 0)) ///
>         prefoot(" ") ///
>         star(* 0.10 ** 0.05 *** 0.01) nonotes
(file 03Output/tables/Table_4.tex not found)
(output written to 03Output/tables/Table_4.tex)

. 
end of do-file

. * Figure F1
. do "$CODE_DIR/make_elasticity_coefplot.do"

. /************************************************************************
> Purpose: Make elasticity coefficients plot in the ETS paper
> *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period-date-bid.dta", clear

. drop if bid_status == "REJ"
(0 observations deleted)

. drop if missing(bid_qty)
(3 observations deleted)

. sort gpcb_id period date bid_id 

. tempfile data_reg

. save `data_reg', replace
(file /var/folders/7r/1zsrb09s0r578bq3nysvhzd40000gn/T//St40195.000001 not found)
file /var/folders/7r/1zsrb09s0r578bq3nysvhzd40000gn/T//St40195.000001 saved as .dta format

. 
. ********************************************************************************
. *** Coefficients plot for Plant x Period FEs by Week
. ********************************************************************************
. 
. clear

. set obs 6
Number of observations (_N) was 0, now 6.

. gen model = .
(6 missing values generated)

. gen coef = .
(6 missing values generated)

. gen lower = .
(6 missing values generated)

. gen upper = .
(6 missing values generated)

. gen nobs = .
(6 missing values generated)

. 
. local price_var ln_bid_price

. local holding_var ln_permit_holding_hyp

. 
. forvalue j = 0/5 {
  2.         
.         preserve
  3.         
.         use `data_reg', clear
  4.                 
.         if `j' == 5 {
  5.                 reghdfe `price_var' `holding_var' if week_left >= `j', a(plant_period_id) vce(cluster gpcb_id)
  6.         } 
  7.         else {
  8.                 reghdfe `price_var' `holding_var' if week_left == `j', a(plant_period_id) vce(cluster gpcb_id)
  9.         }
 10.         
.         restore 
 11.         
.         replace model = `j' if _n == `j'+1
 12.         replace coef = _b[`holding_var'] if _n == `j'+1
 13.         replace lower = _b[`holding_var'] - invttail(e(df_r),0.025)*_se[`holding_var'] if _n == `j'+1
 14.         replace upper = _b[`holding_var'] + invttail(e(df_r),0.025)*_se[`holding_var'] if _n == `j'+1
 15.         replace nobs = e(N) if _n == `j'+1
 16.         
. }
(dropped 478 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      1,257
Absorbing 1 HDFE group                            F(   1,    132) =       1.93
Statistics robust to heteroskedasticity           Prob > F        =     0.1674
                                                  R-squared       =     0.7762
                                                  Adj R-squared   =     0.6581
                                                  Within R-sq.    =     0.0012
Number of clusters (gpcb_id) =        133         Root MSE        =     0.2423

                                       (Std. err. adjusted for 133 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |   .0563015   .0405559     1.39   0.167    -.0239221     .136525
                _cons |   1.692436   .2683759     6.31   0.000     1.161562     2.22331
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       434         434           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(dropped 459 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      1,541
Absorbing 1 HDFE group                            F(   1,    135) =       4.78
Statistics robust to heteroskedasticity           Prob > F        =     0.0306
                                                  R-squared       =     0.6442
                                                  Adj R-squared   =     0.4922
                                                  Within R-sq.    =     0.0051
Number of clusters (gpcb_id) =        136         Root MSE        =     0.4055

                                       (Std. err. adjusted for 136 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |   .1314894    .060167     2.19   0.031     .0124975    .2504813
                _cons |   1.361606   .4164874     3.27   0.001     .5379225     2.18529
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       461         461           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(dropped 298 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      1,089
Absorbing 1 HDFE group                            F(   1,     96) =       1.90
Statistics robust to heteroskedasticity           Prob > F        =     0.1717
                                                  R-squared       =     0.4939
                                                  Adj R-squared   =     0.3134
                                                  Within R-sq.    =     0.0018
Number of clusters (gpcb_id) =         97         Root MSE        =     0.4854

                                        (Std. err. adjusted for 97 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |   .1065194   .0773495     1.38   0.172    -.0470181    .2600569
                _cons |   1.626509   .5593679     2.91   0.005      .516173    2.736846
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       286         286           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(dropped 232 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =        736
Absorbing 1 HDFE group                            F(   1,     76) =       3.59
Statistics robust to heteroskedasticity           Prob > F        =     0.0618
                                                  R-squared       =     0.6340
                                                  Adj R-squared   =     0.5046
                                                  Within R-sq.    =     0.0126
Number of clusters (gpcb_id) =         77         Root MSE        =     0.3987

                                        (Std. err. adjusted for 77 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |   -.347687   .1833871    -1.90   0.062    -.7129342    .0175601
                _cons |   4.971109   1.348727     3.69   0.000     2.284887    7.657331
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       192         192           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(dropped 341 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =        735
Absorbing 1 HDFE group                            F(   1,     88) =      25.49
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5117
                                                  Adj R-squared   =     0.3363
                                                  Within R-sq.    =     0.0668
Number of clusters (gpcb_id) =         89         Root MSE        =     0.5227

                                        (Std. err. adjusted for 89 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.8677084   .1718513    -5.05   0.000    -1.209227     -.52619
                _cons |   8.691534   1.278584     6.80   0.000     6.150618    11.23245
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       194         194           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(dropped 223 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      1,035
Absorbing 1 HDFE group                            F(   1,     96) =      16.50
Statistics robust to heteroskedasticity           Prob > F        =     0.0001
                                                  R-squared       =     0.5814
                                                  Adj R-squared   =     0.4649
                                                  Within R-sq.    =     0.0265
Number of clusters (gpcb_id) =         97         Root MSE        =     0.4337

                                        (Std. err. adjusted for 97 clusters in gpcb_id)
---------------------------------------------------------------------------------------
                      |               Robust
         ln_bid_price | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
----------------------+----------------------------------------------------------------
ln_permit_holding_hyp |  -.3417911   .0841431    -4.06   0.000    -.5088137   -.1747684
                _cons |   4.388874   .6255478     7.02   0.000     3.147172    5.630577
---------------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
-----------------+---------------------------------------|
 plant_period_id |       225         225           0    *|
---------------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)

. 
. gen model_plot = -model

. label define model_plot_values -5 "≥5" -4 "4" -3 "3" -2 "2" -1 "1" 0 "0"

. label values model_plot model_plot_values  

. graph twoway ///
>         (scatter coef model_plot, mcolor("midblue")) (rcap lower upper model_plot, color("midblue")), ///
>         yline(0, lstyle(solid) lcolor(red)) xlabel(-5 "≥5" -4 "4" -3 "3" -2 "2" -1 "1" 0 "0") ///
>         ytitle("Coefficient of log(emissions as bid)") ///
>         xtitle("Weeks remaining") /// 
>         plotregion(color(white)) bgcolor(white) graphregion(color(white) lcolor(white)) legend(off) ///
>         name("graph_1", replace)

.         
. ********************************************************************************
. *** Histogram of number of bids by Week
. ********************************************************************************
.         
. use `data_reg', clear

. gen model_plot = week_left

. replace model_plot = 5 if model_plot > 5
(181 real changes made)

. replace model_plot = -model_plot
(6,694 real changes made)

. hist model_plot, freq discrete width(1) ///
>         xlabel(-5 "≥5" -4 "4" -3 "3" -2 "2" -1 "1" 0 "0") ///
>         color(midblue*0.6) lcolor(midblue) ///
>         xtitle("Weeks remaining") ///
>         plotregion(color(white)) bgcolor(white) graphregion(color(white) lcolor(white)) legend(off) ///
>         name("graph_2", replace) fysize(50)
(start=-5, width=1)

.         
. ********************************************************************************
. *** Combine coefficients plot and histogram
. ********************************************************************************
.         
. graph combine graph_1 graph_2, ///
>         cols(1) ysize(20) xsize(16) xcommon ///
>         graphregion(color(white)) plotregion(color(white) lcolor(white))

.         
. graph export "$TRADING_FIGS/Figure_F1.pdf", replace
file 03Output/figures/Figure_F1.pdf saved as PDF format

. 
end of do-file

. 
. * Table 2
. do "$CODE_DIR/compute_summary_statistics.do"

. /************************************************************************
>            Purpose:     Collect summary statistics of bid prices and quantities
>    *************************************************************************/
. 
. set more off

. clear all

. pause on

. 
. use "$TRADING_DATA_CLEAN/panel_plant-period-date-bid.dta", clear

. drop if bid_status == "REJ"
(0 observations deleted)

. drop if missing(bid_qty)
(3 observations deleted)

. 
. gen bid_qty_abs = abs(bid_qty)

. gen bid_qty_purchase_abs = .
(8,433 missing values generated)

. replace bid_qty_purchase_abs = abs(bid_qty) if bid_qty > 0
(3,520 real changes made)

. gen bid_qty_sale_abs = .
(8,433 missing values generated)

. replace bid_qty_sale_abs = abs(bid_qty) if bid_qty < 0
(4,913 real changes made)

. 
. gen trade_qty_abs = abs(trade_qty)
(4,658 missing values generated)

. gen trade_qty_purchase_abs = .
(8,433 missing values generated)

. replace trade_qty_purchase_abs = abs(trade_qty) if trade_qty > 0
(2,018 real changes made)

. gen trade_qty_sale_abs = .
(8,433 missing values generated)

. replace trade_qty_sale_abs = abs(trade_qty) if trade_qty < 0
(1,757 real changes made)

. 
. gen bid_price_purchase = .
(8,433 missing values generated)

. replace bid_price_purchase = bid_price if bid_qty > 0
(3,520 real changes made)

. gen bid_price_sale = .
(8,433 missing values generated)

. replace bid_price_sale = bid_price if bid_qty < 0
(4,913 real changes made)

. 
. gen trade_price_purchase = .
(8,433 missing values generated)

. replace trade_price_purchase = trade_price if trade_qty > 0
(2,018 real changes made)

. gen trade_price_sale = .
(8,433 missing values generated)

. replace trade_price_sale = trade_price if trade_qty < 0
(1,757 real changes made)

. 
. sum bid_qty_*abs trade_qty_*abs bid_price* trade_price*

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |      8,433     411.606     707.976          1      12961
bid_qty_pu~s |      3,520    429.5043    565.0898          1       5131
bid_qty_sa~s |      4,913    398.7824    794.5157          1      12961
trade_~y_abs |      3,775    360.4172    564.4534          1      12961
trade~se_abs |      2,018    389.3578    544.0851          1       5131
-------------+---------------------------------------------------------
trade~le_abs |      1,757    327.1776    585.3682          1      12961
   bid_price |      8,433    11.24712      11.556          5        100
bid_price~se |      3,520    9.466761    10.49622          5        100
bid_price~le |      4,913    12.52269     12.1001          5        100
 trade_price |      3,775    9.285828    7.385706          5        100
-------------+---------------------------------------------------------
trade_pri~se |      2,018    9.185828    9.310842          5        100
trade_pri~le |      1,757    9.400683    4.199327          5         16

. 
. tempfile cleaned_data

. save `cleaned_data'
file /var/folders/7r/1zsrb09s0r578bq3nysvhzd40000gn/T//St40195.000001 saved as .dta format

. 
. matrix data = J(14, 3, 0)

. 
. ********************************************************************************
. *** Version 1, Panel A: Bids
. ********************************************************************************
. 
. ** Unweighted
. local counter = 1

. foreach var of varlist bid_qty_*abs {
  2.         sum `var'
  3.         matrix data[1, `counter'] = r(mean)
  4.         matrix data[2, `counter'] = r(sd)
  5.         local counter = `counter' + 1
  6. }

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |      8,433     411.606     707.976          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |      3,520    429.5043    565.0898          1       5131

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |      4,913    398.7824    794.5157          1      12961

. 
. local counter = 1

. foreach var of varlist bid_price*{
  2.         sum `var'
  3.         matrix data[3, `counter'] = r(mean)
  4.         matrix data[4, `counter'] = r(sd)
  5.         local counter = `counter' + 1
  6. }

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |      8,433    11.24712      11.556          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |      3,520    9.466761    10.49622          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |      4,913    12.52269     12.1001          5        100

. 
. ** Weighted
. sum bid_price [aweight=bid_qty_abs]

    Variable |     Obs      Weight        Mean   Std. dev.       Min        Max
-------------+-----------------------------------------------------------------
   bid_price |   8,433     3471073    9.233128   8.490935          5        100

. matrix data[5, 1] = r(mean)

. matrix data[6, 1] = r(sd)

. matrix data[7, 1] = r(N)

. 
. local counter = `counter' + 1

. sum bid_price_purchase [aweight=bid_qty_purchase_abs]

    Variable |     Obs      Weight        Mean   Std. dev.       Min        Max
-------------+-----------------------------------------------------------------
bid_price~se |   3,520     1511855    8.424174   8.708539          5        100

. matrix data[5, 2] = r(mean)

. matrix data[6, 2] = r(sd)

. matrix data[7, 2] = r(N)

. 
. local counter = `counter' + 1

. sum bid_price_sale [aweight=bid_qty_sale_abs]

    Variable |     Obs      Weight        Mean   Std. dev.       Min        Max
-------------+-----------------------------------------------------------------
bid_price~le |   4,913     1959218    9.857367   8.266113          5        100

. matrix data[5, 3] = r(mean)

. matrix data[6, 3] = r(sd)

. matrix data[7, 3] = r(N)

. 
. ********************************************************************************
. *** Version 1, Panel B: Trade
. ********************************************************************************
. 
. ** Unweighted
. local counter = 1

. foreach var of varlist trade_qty_*abs {
  2.         sum `var'
  3.         matrix data[8, `counter'] = r(mean)
  4.         matrix data[9, `counter'] = r(sd)
  5.         local counter = `counter' + 1
  6. }

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
trade_~y_abs |      3,775    360.4172    564.4534          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
trade~se_abs |      2,018    389.3578    544.0851          1       5131

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
trade~le_abs |      1,757    327.1776    585.3682          1      12961

. 
. local counter = 1

. foreach var of varlist trade_price* {
  2.         sum `var'
  3.         matrix data[10, `counter'] = r(mean)
  4.         matrix data[11, `counter'] = r(sd)
  5.         local counter = `counter' + 1
  6. }

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 trade_price |      3,775    9.285828    7.385706          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
trade_pri~se |      2,018    9.185828    9.310842          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
trade_pri~le |      1,757    9.400683    4.199327          5         16

. 
. ** Weighted
. local counter = `counter' + 1

. sum trade_price [aweight=trade_qty_abs]

    Variable |     Obs      Weight        Mean   Std. dev.       Min        Max
-------------+-----------------------------------------------------------------
 trade_price |   3,775     1360575    8.400857   6.165365          5        100

. matrix data[12, 1] = r(mean)

. matrix data[13, 1] = r(sd)

. matrix data[14, 1] = r(N)

. 
. local counter = `counter' + 1

. sum trade_price_purchase [aweight=trade_qty_purchase_abs]

    Variable |     Obs      Weight        Mean   Std. dev.       Min        Max
-------------+-----------------------------------------------------------------
trade_pri~se |   2,018      785724    8.156418    7.25991          5        100

. matrix data[12, 2] = r(mean)

. matrix data[13, 2] = r(sd)

. matrix data[14, 2] = r(N)

. 
. local counter = `counter' + 1

. sum trade_price_sale [aweight=trade_qty_sale_abs]

    Variable |     Obs      Weight        Mean   Std. dev.       Min        Max
-------------+-----------------------------------------------------------------
trade_pri~le |   1,757      574851    8.734964   4.213717          5         16

. matrix data[12, 3] = r(mean)

. matrix data[13, 3] = r(sd)

. matrix data[14, 3] = r(N)

. 
. matrix colnames data = ///
>         "All" ///
>         "Purchase" ///
>         "Sale"

.         
. *** Output
. clear 

. svmat double data, names(col)
number of observations will be reset to 14
Press any key to continue, or Break to abort
Number of observations (_N) was 0, now 14.

. 
. foreach table_panel in "A" "B" {
  2.         preserve
  3.         * Select observations
.         if "`table_panel'" == "A" {
  4.                 drop if _n > 7
  5.         }
  6.         if "`table_panel'" == "B" {
  7.                 drop if _n < 8
  8.         }
  9. 
.         * Cleanup vars
.         foreach v of varlist * {
 10.         gen `v'_str = string(round(`v', 0.01), "%9.2f")
 11.         replace `v'_str = string(`v', "%9.0f") if mod(_n, 7) == 0
 12.         replace `v'_str = "(" + `v'_str + ")"  if mod(_n, 2) == 0 & _n != 7
 13.         replace `v'_str = "\multicolumn{1}{c}{" + `v'_str + "}"
 14.         drop `v'
 15.         rename `v'_str `v'
 16. }
 17. 
.         * Set varnames
.         local rname_type = "Order"
 18.         if "`table_panel'" == "B" local rname_type = "Trade"
 19. 
.         gen rname = "", before("All")
 20.         replace rname = "`rname_type' quantity (kg)" if _n == 1
 21.         replace rname = "`rname_type' price (Rs/kg)" if _n == 3
 22.         replace rname = "`rname_type' price (Rs/kg), weighted by quantity" if _n == 5
 23.         replace rname = "Observations" if _n == 7
 24. 
.         * Add empty row
.         qui: ds 
 25.         gen last = _n == _N
 26.         expand 2 if last, gen(dup)
 27.         foreach var in `r(varlist)' {
 28.                 replace `var' = "\multicolumn{1}{c}{}" if dup == 0 & last == 1
 29.         }
 30.         drop last dup
 31. 
.         listtex using "$TRADING_TABS/Table_B1_`table_panel'.tex", rstyle(tabular) replace
 32.         restore
 33. }
(7 observations deleted)
(1 real change made)
variable All_str was str7 now str8
(3 real changes made)
variable All_str was str8 now str28
(7 real changes made)
(1 real change made)
variable Purchase_str was str7 now str8
(3 real changes made)
variable Purchase_str was str8 now str28
(7 real changes made)
(1 real change made)
variable Sale_str was str7 now str8
(3 real changes made)
variable Sale_str was str8 now str28
(7 real changes made)
(7 missing values generated)
variable rname was str1 now str19
(1 real change made)
(1 real change made)
variable rname was str19 now str41
(1 real change made)
(1 real change made)
(1 observation created)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(file 03Output/tables/Table_B1_A.tex not found)
(7 observations deleted)
(1 real change made)
variable All_str was str7 now str8
(3 real changes made)
variable All_str was str8 now str28
(7 real changes made)
(1 real change made)
variable Purchase_str was str7 now str8
(3 real changes made)
variable Purchase_str was str8 now str28
(7 real changes made)
(1 real change made)
variable Sale_str was str7 now str8
(3 real changes made)
variable Sale_str was str8 now str28
(7 real changes made)
(7 missing values generated)
variable rname was str1 now str19
(1 real change made)
(1 real change made)
variable rname was str19 now str41
(1 real change made)
(1 real change made)
(1 observation created)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(file 03Output/tables/Table_B1_B.tex not found)

. 
. 
. 
. 
. ********************************************************************************
. *** Version 2, Detail
. ********************************************************************************
. use `cleaned_data', clear

. 
. bysort gpcb_id period: gen num_bids = _N

. bysort gpcb_id: gen num_bids_total = _N

. 
. matrix data = J(33, 9, 0)

. forvalues period = 1/10 {
  2.         * Fill period
.         matrix data[3*`period'-2, 1] = `period'
  3.         matrix data[3*`period'-1, 1] = .
  4.         matrix data[3*`period', 1] = .
  5.         
.         matrix data[3*`period'-2, 2] = .
  6.         matrix data[3*`period'-1, 2] = .
  7.         matrix data[3*`period', 2] = .
  8.         
.         sum num_bids if period == `period'
  9.         matrix data[3*`period' - 2, 2] = r(N)
 10.         local counter = 3
 11.         foreach var of varlist num_bids bid_qty_abs bid_qty_purchase_abs bid_qty_sale_abs bid_price bid_price_purchase bid_price_sale {
 12.                 sum `var' if period == `period'
 13.                 if ("`var'" == "num_bids"){
 14.                         preserve
 15.                         keep if period == `period'
 16.                         keep gpcb_id commodity num_bids
 17.                         merge m:1 gpcb_id commodity using "$TRADING_DATA_OUT/inventory_plant-commodity.dta", keepusing(commodity_period)
 18.                         replace num_bids = 0 if missing(num_bids)
 19.                         keep if commodity_period == `period'
 20.                         duplicates drop
 21.                         sum `var'
 22.                         matrix data[3*`period'-2, `counter'] = round(r(mean), 0.01)
 23.                         matrix data[3*`period'-1, `counter'] = round(r(sd), 0.01)
 24.                         matrix data[3*`period', `counter'] = .
 25.                         restore
 26.                 } 
 27.                 else {
 28.                         sum `var' if period == `period'
 29.                         matrix data[3*`period'-2, `counter'] = round(r(mean), 0.01)
 30.                         matrix data[3*`period'-1, `counter'] = round(r(sd), 0.01)
 31.                         matrix data[3*`period', `counter'] = .
 32.                 }
 33. 
.                 local counter = `counter' + 1
 34.         }
 35. }

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |      1,525    20.82295    14.27537          1         54

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |      1,525    20.82295    14.27537          1         54
(6,908 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,419
        from master                         0  (_merge==1)
        from using                      1,419  (_merge==2)

    Matched                             1,525  (_merge==3)
    -----------------------------------------
(1,419 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(1,384 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    9.775641    10.42551          0         54

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |      1,525    556.6538    1171.776          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |      1,525    556.6538    1171.776          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        500     427.652    604.3647          1       5131

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        500     427.652    604.3647          1       5131

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |      1,025    619.5815    1361.403          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |      1,025    619.5815    1361.403          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |      1,525    12.70033    16.64769          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |      1,525    12.70033    16.64769          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        500      10.032    14.47335          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        500      10.032    14.47335          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |      1,025    14.00195    17.47051          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |      1,025    14.00195    17.47051          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        600    8.156667     6.00824          1         22

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        600    8.156667     6.00824          1         22
(7,833 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,424
        from master                         0  (_merge==1)
        from using                      1,424  (_merge==2)

    Matched                               600  (_merge==3)
    -----------------------------------------
(1,424 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(464 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    3.846154    4.084832          0         22

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        600    474.4983    747.1144          4       5830

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        600    474.4983    747.1144          4       5830

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        157    474.5987    534.6557          4       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        157    474.5987    534.6557          4       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        443    474.4628    809.6646          5       5830

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        443    474.4628    809.6646          5       5830

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        600    7.898333    10.71663          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        600    7.898333    10.71663          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        157    6.388535    9.155109          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        157    6.388535    9.155109          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        443    8.433409     11.1786          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        443    8.433409     11.1786          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |      1,084    13.43727    10.51669          1         46

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |      1,084    13.43727    10.51669          1         46
(7,349 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,414
        from master                         0  (_merge==1)
        from using                      1,414  (_merge==2)

    Matched                             1,084  (_merge==3)
    -----------------------------------------
(1,414 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(938 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    6.948718    6.736319          0         46

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |      1,084    329.2906    532.5904          1       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |      1,084    329.2906    532.5904          1       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        318    344.4906    599.9628          1       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        318    344.4906    599.9628          1       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        766    322.9804    502.2639          1       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        766    322.9804    502.2639          1       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |      1,084    10.89114    11.36164          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |      1,084    10.89114    11.36164          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        318    9.022013    12.23854          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        318    9.022013    12.23854          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        766     11.6671    10.89151          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        766     11.6671    10.89151          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        806    12.33002    12.66119          1         54

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        806    12.33002    12.66119          1         54
(7,627 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,419
        from master                         0  (_merge==1)
        from using                      1,419  (_merge==2)

    Matched                               806  (_merge==3)
    -----------------------------------------
(1,419 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(665 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    5.166667    6.103234          0         54

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        806    322.7444    550.9261          1       6879

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        806    322.7444    550.9261          1       6879

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        225    332.2622    483.4122          1       3500

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        225    332.2622    483.4122          1       3500

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        581    319.0585    575.2945          1       6879

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        581    319.0585    575.2945          1       6879

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        806    10.87841    9.365596          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        806    10.87841    9.365596          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        225    7.902222    6.767784          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        225    7.902222    6.767784          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        581    12.03098    9.964198          5         90

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        581    12.03098    9.964198          5         90

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        767    14.78618    17.89296          1         67

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        767    14.78618    17.89296          1         67
(7,666 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,416
        from master                         0  (_merge==1)
        from using                      1,416  (_merge==2)

    Matched                               767  (_merge==3)
    -----------------------------------------
(1,416 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(623 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    4.916667    6.988431          0         67

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        767    375.8605    514.9452          1       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        767    375.8605    514.9452          1       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        203    448.6256    559.3544         10       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        203    448.6256    559.3544         10       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        564    349.6702    495.9089          1       3069

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        564    349.6702    495.9089          1       3069

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        767    9.603651    10.79887          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        767    9.603651    10.79887          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        203    6.492611    1.735961          5         15

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        203    6.492611    1.735961          5         15

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        564     10.7234     12.3627          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        564     10.7234     12.3627          5         95

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        296    7.243243    5.876839          1         22

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        296    7.243243    5.876839          1         22
(8,137 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,478
        from master                         0  (_merge==1)
        from using                      1,478  (_merge==2)

    Matched                               296  (_merge==3)
    -----------------------------------------
(1,478 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(214 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    1.897436    3.195116          0         22

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        296    463.1554    557.9793          5       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        296    463.1554    557.9793          5       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        102    533.4216    558.5859         20       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        102    533.4216    558.5859         20       4000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        194    426.2113    555.5343          5       3618

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        194    426.2113    555.5343          5       3618

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        296    7.503378    6.328305          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        296    7.503378    6.328305          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        102    5.843137    3.110968          5         35

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        102    5.843137    3.110968          5         35

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        194    8.376289    7.343366          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        194    8.376289    7.343366          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        646    9.086687    8.735311          1         37

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        646    9.086687    8.735311          1         37
(7,787 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,415
        from master                         0  (_merge==1)
        from using                      1,415  (_merge==2)

    Matched                               646  (_merge==3)
    -----------------------------------------
(1,415 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(501 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    4.141026    4.540071          0         37

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        646     399.822    532.7977          1       5387

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        646     399.822    532.7977          1       5387

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        337    468.3086    579.8769          1       4066

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        337    468.3086    579.8769          1       4066

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        309    325.1294    465.7467          1       5387

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        309    325.1294    465.7467          1       5387

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        646    12.76161    6.547298          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        646    12.76161    6.547298          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        337     10.2908    4.806215          5         25

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        337     10.2908    4.806215          5         25

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        309    15.45631    7.113792          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        309    15.45631    7.113792          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        783    13.00255     11.4859          1         42

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        783    13.00255     11.4859          1         42
(7,650 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,413
        from master                         0  (_merge==1)
        from using                      1,413  (_merge==2)

    Matched                               783  (_merge==3)
    -----------------------------------------
(1,413 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(636 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    5.019231    6.350485          0         42

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        783    418.2414    587.8469          2       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        783    418.2414    587.8469          2       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        527     500.518     670.722          2       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        527     500.518     670.722          2       5000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        256    248.8672    298.2886          2       2052

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        256    248.8672    298.2886          2       2052

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        783    13.50958     13.9157          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        783    13.50958     13.9157          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        527    12.55598    16.52766          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        527    12.55598    16.52766          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        256    15.47266     4.96332          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        256    15.47266     4.96332          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        962    21.34927    21.47599          1         74

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        962    21.34927    21.47599          1         74
(7,471 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,415
        from master                         0  (_merge==1)
        from using                      1,415  (_merge==2)

    Matched                               962  (_merge==3)
    -----------------------------------------
(1,415 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(817 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    6.166667    9.707219          0         74

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        962    353.4574    422.9548          1       3514

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        962    353.4574    422.9548          1       3514

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        663    396.7964    457.5429          1       3514

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        663    396.7964    457.5429          1       3514

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        299    257.3579    313.6744          1       2000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        299    257.3579    313.6744          1       2000

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        962    11.40852    6.651144          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        962    11.40852    6.651144          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        663    9.889894    7.002693          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        663    9.889894    7.002693          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        299    14.77592    4.149063          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        299    14.77592    4.149063          5         50

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        964    18.76349    17.80161          1         59

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        964    18.76349    17.80161          1         59
(7,469 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,416
        from master                         0  (_merge==1)
        from using                      1,416  (_merge==2)

    Matched                               964  (_merge==3)
    -----------------------------------------
(1,416 real changes made)
(1,404 observations deleted)

Duplicates in terms of all variables

(820 observations deleted)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    num_bids |        156    6.179487    8.846714          0         59

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        964    383.0093    533.0626          1       3964

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |        964    383.0093    533.0626          1       3964

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        488    428.4037    531.7224          1       3964

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |        488    428.4037    531.7224          1       3964

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        476    336.4706    530.9704          1       3441

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |        476    336.4706    530.9704          1       3441

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        964    11.18465     9.10166          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |        964    11.18465     9.10166          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        488    8.403689    5.646222          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |        488    8.403689    5.646222          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        476    14.03571    10.91656          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |        476    14.03571    10.91656          5        100

. 
. 
. local period = 11

. local counter = 3

. matrix data[3*`period'-2, 1] = `period'

. matrix data[3*`period'-1, 1] = .

. matrix data[3*`period', 1] = .

. 
. sum num_bids_total

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
num_bids_t~l |      8,433    101.8531    82.55766          1        346

. matrix data[3*`period' - 2, 2] = r(N)

. matrix data[3*`period'-1, 2] = .

. matrix data[3*`period', 2] = .

. local counter = 3

. foreach var of varlist num_bids_total bid_qty_abs bid_qty_purchase_abs bid_qty_sale_abs bid_price bid_price_purchase bid_price_sale {
  2.         if "`var'" == "num_bids_total" {
  3.                 preserve
  4.                 keep gpcb_id num_bids_total
  5.                 duplicates drop
  6.                 merge 1:1 gpcb_id using "$TRADING_DATA_OUT/index_plant.dta"
  7.                 replace num_bids_total = 0 if missing(num_bids_total) 
  8.                 sum `var'
  9.                 matrix data[3*`period'-2, `counter'] = round(r(mean), 0.01)
 10.                 matrix data[3*`period'-1, `counter'] = round(r(sd), 0.01)
 11.                 matrix data[3*`period', `counter'] = .          
 12.                 restore
 13.         } 
 14.         else {
 15.                 sum `var'
 16.                 matrix data[3*`period'-2, `counter'] = round(r(mean), 0.01)
 17.                 matrix data[3*`period'-1, `counter'] = round(r(sd), 0.01)
 18.                 matrix data[3*`period', `counter'] = .
 19.                 }
 20.         
.         local counter = `counter' + 1
 21. }

Duplicates in terms of all variables

(8,280 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             3
        from master                         0  (_merge==1)
        from using                          3  (_merge==2)

    Matched                               153  (_merge==3)
    -----------------------------------------
(3 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
num_bids_t~l |        156    54.05769    50.99389          0        346

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 bid_qty_abs |      8,433     411.606     707.976          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_pu~s |      3,520    429.5043    565.0898          1       5131

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_qty_sa~s |      4,913    398.7824    794.5157          1      12961

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
   bid_price |      8,433    11.24712      11.556          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~se |      3,520    9.466761    10.49622          5        100

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
bid_price~le |      4,913    12.52269     12.1001          5        100

. 
.         
. **** Output
. clear 

. svmat double data, names(col)
number of observations will be reset to 33
Press any key to continue, or Break to abort
Number of observations (_N) was 0, now 33.

. 
. * Cleanup vars
. foreach v of varlist * {
  2.         if inlist("`v'", "c7", "c8", "c9") {
  3.                 gen `v'_str = string(round(`v', 0.01), "%9.2f")
  4.         }
  5.         else if "`v'" == "c3" {
  6.                 gen `v'_str = string(round(`v', 0.1), "%9.1f")
  7.         }
  8.         else {
  9.                 gen `v'_str = string(`v', "%9.0fc")
 10.         }
 11.         replace `v'_str = "" if `v'_str == "."
 12.         replace `v'_str = "(" + `v'_str + ")" if mod(_n, 3) == 2 & `v'_str != ""
 13.         replace `v'_str = "Total" if _n == 31 & "`v'" == "c1"
 14.         drop `v'
 15.         rename `v'_str `v'
 16. }
(22 real changes made)
(0 real changes made)
variable c1_str was str2 now str5
(1 real change made)
(22 real changes made)
(0 real changes made)
(0 real changes made)
(11 real changes made)
variable c3_str was str4 now str6
(11 real changes made)
(0 real changes made)
(11 real changes made)
variable c4_str was str5 now str7
(11 real changes made)
(0 real changes made)
(11 real changes made)
variable c5_str was str3 now str5
(11 real changes made)
(0 real changes made)
(11 real changes made)
variable c6_str was str5 now str7
(11 real changes made)
(0 real changes made)
(11 real changes made)
variable c7_str was str5 now str7
(11 real changes made)
(0 real changes made)
(11 real changes made)
variable c8_str was str5 now str7
(11 real changes made)
(0 real changes made)
(11 real changes made)
variable c9_str was str5 now str7
(11 real changes made)
(0 real changes made)

. drop if _n == _N
(1 observation deleted)

. listtex using "$TRADING_TABS/Table_2.tex", rstyle(tabular) replace ///
> headlines("\begin{tabular}{c*{8}{c}} \toprule &  & & \multicolumn{3}{c}{Bid quantities (kg)} & \multicolumn{3}{c}{Bid prices (INR/kg)} \\ \cmidrule(lr){4-6} \cmidrule(lr){7-9} \multicolumn{1}{c}{Period} & \multicolumn{1}{c}{Count} & \multicolumn{1}{c}{B
> ids per plant} & \multicolumn{1}{c}{All bids} & \multicolumn{1}{c}{Buy bids} & \multicolumn{1}{c}{Sell bids} & \multicolumn{1}{c}{All bids} & \multicolumn{1}{c}{Buy bids} & \multicolumn{1}{c}{Sell bids} \\ & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{
> (2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)} & \multicolumn{1}{c}{(7)} & \multicolumn{1}{c}{(8)} \\ \midrule") ///
> footlines("\addlinespace \bottomrule \end{tabular}")
(file 03Output/tables/Table_2.tex not found)

. 
end of do-file

. 
. 
end of do-file
